[GRASS-SVN] r62692 - in grass/branches/releasebranch_7_0: . raster/r.param.scale

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 10 07:35:05 PST 2014


Author: annakrat
Date: 2014-11-10 07:35:05 -0800 (Mon, 10 Nov 2014)
New Revision: 62692

Modified:
   grass/branches/releasebranch_7_0/
   grass/branches/releasebranch_7_0/raster/r.param.scale/find_normal.c
   grass/branches/releasebranch_7_0/raster/r.param.scale/process.c
Log:
r.param.scale: propagate NULL values instead of ignoring them - #2466 (merge from trunk, r62648)


Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/trunk:61096,62179-62180,62182,62403,62422,62424,62437,62466,62487,62491,62494,62501,62506,62508-62509,62515,62518-62519,62521,62526,62533,62539,62541,62555,62562,62570,62573,62575,62585,62588,62597,62603,62606,62609,62614,62618,62628,62632,62638,62642,62649,62652,62655-62657,62666
   + /grass/trunk:61096,62179-62180,62182,62403,62422,62424,62437,62466,62487,62491,62494,62501,62506,62508-62509,62515,62518-62519,62521,62526,62533,62539,62541,62555,62562,62570,62573,62575,62585,62588,62597,62603,62606,62609,62614,62618,62628,62632,62638,62642,62648-62649,62652,62655-62657,62666

Modified: grass/branches/releasebranch_7_0/raster/r.param.scale/find_normal.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.param.scale/find_normal.c	2014-11-10 15:29:52 UTC (rev 62691)
+++ grass/branches/releasebranch_7_0/raster/r.param.scale/find_normal.c	2014-11-10 15:35:05 UTC (rev 62692)
@@ -16,7 +16,7 @@
 
     /* on computation               */
 
-    float x, y,			/* Local coordinates of window. */
+    double x, y,			/* Local coordinates of window. */
       x1 = 0, y1 = 0,		/* coefficients of X-products.  */
 	x2 = 0, y2 = 0,
 	x3 = 0, y3 = 0,
@@ -110,7 +110,7 @@
       edge = EDGE,		/* EDGE = (wsize-1)/2.          */
 	offset;			/* Array offset for weights & z */
 
-    float x, y;			/* Local window coordinates.    */
+    double x, y;			/* Local window coordinates.    */
 
     for (row = 0; row < 6; row++)	/* Initialise column vector.        */
 	obs[row] = 0.0;

Modified: grass/branches/releasebranch_7_0/raster/r.param.scale/process.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.param.scale/process.c	2014-11-10 15:29:52 UTC (rev 62691)
+++ grass/branches/releasebranch_7_0/raster/r.param.scale/process.c	2014-11-10 15:35:05 UTC (rev 62692)
@@ -36,7 +36,8 @@
 	/* raster row, each element is of type  */
 	/* DCELL        */
 	*window_ptr,		/* Stores local terrain window.         */
-	centre;			/* Elevation of central cell in window. */
+	centre,			/* Elevation of central cell in window. */
+	*window_cell;		/* Stores last read cell in window. */
 
     CELL *featrow_out = NULL;	/* store features in CELL */
 
@@ -55,8 +56,8 @@
       temp;			/* Unused */
 
     double *weight_ptr;		/* Weighting matrix for observed values. */
+    int found_null;             /* If null was found among window cells  */
 
-
     /*--------------------------------------------------------------------------*/
     /*                     GET RASTER AND WINDOW DETAILS                        */
 
@@ -86,10 +87,14 @@
     row_in = (DCELL *) G_malloc(ncols * sizeof(DCELL) * wsize);
     /* Reserve `wsize' rows of memory.      */
 
-    if (mparam != FEATURE)
+    if (mparam != FEATURE) {
 	row_out = Rast_allocate_buf(DCELL_TYPE);	/* Initialise output row buffer.     */
-    else
+	Rast_set_d_null_value(row_out, ncols);
+    }
+    else {
 	featrow_out = Rast_allocate_buf(CELL_TYPE);	/* Initialise output row buffer.  */
+	Rast_set_c_null_value(featrow_out, ncols);
+    }
 
     window_ptr = (DCELL *) G_malloc(SQR(wsize) * sizeof(DCELL));
     /* Reserve enough memory for local wind. */
@@ -167,16 +172,41 @@
 	for (col = EDGE; col < (ncols - EDGE); col++) {
 	    /* Find central z value */
 	    centre = *(row_in + EDGE * ncols + col);
+	    /* Test for no data and propagate */
+	    if (Rast_is_d_null_value(&centre)) {
+		if (mparam == FEATURE)
+		    Rast_set_c_null_value(featrow_out + col, 1);
+		else {
+		    Rast_set_d_null_value(row_out + col, 1);
+		}
+		continue;
+	    }
+	    found_null = FALSE;
+	    for (wind_row = 0; wind_row < wsize; wind_row++) {
+		if (found_null)
+		    break;
+		for (wind_col = 0; wind_col < wsize; wind_col++) {
 
-	    for (wind_row = 0; wind_row < wsize; wind_row++)
-		for (wind_col = 0; wind_col < wsize; wind_col++)
-
 		    /* Express all window values relative   */
 		    /* to the central elevation.            */
+		    window_cell = row_in + (wind_row * ncols) + col + wind_col - EDGE;
+		    /* Test for no data and propagate */
+		    if (Rast_is_d_null_value(window_cell)) {
+			if (mparam == FEATURE)
+			    Rast_set_c_null_value(featrow_out + col, 1);
+			else {
+			    Rast_set_d_null_value(row_out + col, 1);
+			}
+			found_null = TRUE;
+			break;
+		    }
 		    *(window_ptr + (wind_row * wsize) + wind_col) =
-			*(row_in + (wind_row * ncols) + col + wind_col -
-			  EDGE) - centre;
+			*(window_cell) - centre;
+		}
+	    }
 
+	    if (found_null)
+		continue;
 
 	    /*--- Use LU back substitution to solve normal equations. ---*/
 	    find_obs(window_ptr, obs_ptr, weight_ptr);
@@ -225,6 +255,10 @@
 		    *(row_in + ((wind_row + 1) * ncols) + col);
     }
 
+    if (mparam != FEATURE)
+	Rast_set_d_null_value(row_out, ncols);
+    else
+	Rast_set_c_null_value(featrow_out, ncols);
     for (wind_row = 0; wind_row < EDGE; wind_row++) {
 	if (mparam != FEATURE)
 	    Rast_put_row(fd_out, row_out, DCELL_TYPE);	/* Write out the edge cells as NULL. */



More information about the grass-commit mailing list