[GRASS-SVN] r69861 - grass-addons/grass7/raster/r.series.lwr

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 21 12:38:08 PST 2016


Author: mmetz
Date: 2016-11-21 12:38:08 -0800 (Mon, 21 Nov 2016)
New Revision: 69861

Modified:
   grass-addons/grass7/raster/r.series.lwr/main.c
Log:
r.series.lwr: add flag to avoid extrapolation

Modified: grass-addons/grass7/raster/r.series.lwr/main.c
===================================================================
--- grass-addons/grass7/raster/r.series.lwr/main.c	2016-11-21 20:37:36 UTC (rev 69860)
+++ grass-addons/grass7/raster/r.series.lwr/main.c	2016-11-21 20:38:08 UTC (rev 69861)
@@ -144,7 +144,7 @@
 	/* co-linear points result in an undefined matrix, and nearly */
 	/* co-linear points results in a solution with rounding error */
 
-	if (pivot == 0.0) {
+	if (fabs(pivot) < GRASS_EPSILON) {
 	    G_debug(4, "Matrix is unsolvable");
 	    return 0;
 	}
@@ -224,7 +224,7 @@
     } parm;
     struct
     {
-	struct Flag *lo, *hi, *lazy;
+	struct Flag *lo, *hi, *lazy, *int_only;
     } flag;
     int i, j, k, n;
     int num_inputs, in_lo, in_hi;
@@ -247,6 +247,7 @@
     int dod;
     int *isnull, n_nulls;
     int min_points, n_points;
+    int first, last, interp_only;
     int this_margin;
     double max_ts, tsdiff1, tsdiff2;
     double delta;
@@ -338,6 +339,10 @@
     flag.lazy->key = 'z';
     flag.lazy->description = _("Don't keep files open");
 
+    flag.int_only = G_define_flag();
+    flag.int_only->key = 'i';
+    flag.int_only->description = _("Do not extrapolate, only interpolate");
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -401,6 +406,8 @@
 	G_fatal_error(_("Unknown weighing function '%s'"),
 	              parm.weight->answer);
 
+    interp_only = flag.int_only->answer;
+
     /* process the input maps from the file */
     if (parm.file->answer) {
 	FILE *in;
@@ -554,6 +561,7 @@
 
 	for (col = 0; col < ncols; col++) {
 
+	    first = last = -1;
 	    n_nulls = 0;
 	    for (i = 0; i < num_inputs; i++) {
 		DCELL v = inputs[i].buf[col];
@@ -568,13 +576,22 @@
 		    isnull[i] = 1;
 		    n_nulls++;
 		}
+		else {
+		    if (first == -1)
+			first = i;
+		    last = i;
+		}
 		values[i] = v;
 	    }
+	    if (!interp_only) {
+		first = 0;
+		last = num_inputs - 1;
+	    }
 
 	    /* LWR */
 	    if (num_inputs - n_nulls >= min_points) {
 
-		for (i = 0; i < num_inputs; i++) {
+		for (i = first; i <= last; i++) {
 		    DCELL result;
 
 		    /* margin around i */



More information about the grass-commit mailing list