[GRASS-SVN] r67620 - grass/trunk/raster/r.grow.distance

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 21 05:23:39 PST 2016


Author: neteler
Date: 2016-01-21 05:23:39 -0800 (Thu, 21 Jan 2016)
New Revision: 67620

Modified:
   grass/trunk/raster/r.grow.distance/
   grass/trunk/raster/r.grow.distance/main.c
   grass/trunk/raster/r.grow.distance/r.grow.distance.html
Log:
r.grow.distance: new flag to calculate distance to nearest NULL cell (trac #2368)


Property changes on: grass/trunk/raster/r.grow.distance
___________________________________________________________________
Modified: svn:ignore
   - OBJ.*

   + OBJ.*
*.tmp.html


Modified: grass/trunk/raster/r.grow.distance/main.c
===================================================================
--- grass/trunk/raster/r.grow.distance/main.c	2016-01-21 11:46:54 UTC (rev 67619)
+++ grass/trunk/raster/r.grow.distance/main.c	2016-01-21 13:23:39 UTC (rev 67620)
@@ -128,7 +128,7 @@
     } opt;
     struct
     {
-	struct Flag *m;
+	struct Flag *m, *n;
     } flag;
     const char *in_name;
     const char *dist_name;
@@ -144,6 +144,7 @@
     DCELL min, max;
     DCELL *out_row;
     double scale = 1.0;
+    int invert;
 
     G_gisinit(argv[0]);
 
@@ -180,6 +181,10 @@
     flag.m->key = 'm';
     flag.m->description = _("Output distances in meters instead of map units");
 
+    flag.n = G_define_flag();
+    flag.n->key = 'n';
+    flag.n->description = _("Calculate distance to nearest NULL cell");
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -187,6 +192,15 @@
     dist_name = opt.dist->answer;
     val_name = opt.val->answer;
 
+    if ((invert = flag.n->answer)) {
+	if (!dist_name)
+	    G_fatal_error(_("Distance output is required for distance to NULL cells"));
+	if (val_name) {
+	    G_warning(_("Value output is meaningless for distance to NULL cells"));
+	    val_name = NULL;
+	}
+    }
+
     if (!dist_name && !val_name)
 	G_fatal_error(_("At least one of distance= and value= must be given"));
 
@@ -274,13 +288,14 @@
 
 	Rast_get_d_row(in_fd, in_row, irow);
 
-	for (col = 0; col < ncols; col++)
-	    if (!Rast_is_d_null_value(&in_row[col])) {
+	for (col = 0; col < ncols; col++) {
+	    if (Rast_is_d_null_value(&in_row[col]) == invert) {
 		new_x_row[col] = 0;
 		new_y_row[col] = 0;
 		dist_row[col] = 0;
 		new_val_row[col] = in_row[col];
 	    }
+	}
 
 	for (col = 0; col < ncols; col++)
 	    check(irow, col, -1, 0);

Modified: grass/trunk/raster/r.grow.distance/r.grow.distance.html
===================================================================
--- grass/trunk/raster/r.grow.distance/r.grow.distance.html	2016-01-21 11:46:54 UTC (rev 67619)
+++ grass/trunk/raster/r.grow.distance/r.grow.distance.html	2016-01-21 13:23:39 UTC (rev 67620)
@@ -6,6 +6,9 @@
 
 <h2>NOTES</h2>
 
+The flag <b>-n</b> calculates the respective pixel distances to the
+nearest NULL cell.
+<p>
 The user has the option of specifying five different metrics which
 control the geometry in which grown cells are created, (controlled by
 the <b>metric</b> parameter): <i>Euclidean</i>, <i>Squared</i>,



More information about the grass-commit mailing list