Explorar o código

r.grow.distance: new flag to calculate distance to nearest NULL cell (trac https://trac.osgeo.org/grass/ticket/2368)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67620 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler %!s(int64=9) %!d(string=hai) anos
pai
achega
a81ccb181c
Modificáronse 2 ficheiros con 21 adicións e 3 borrados
  1. 18 3
      raster/r.grow.distance/main.c
  2. 3 0
      raster/r.grow.distance/r.grow.distance.html

+ 18 - 3
raster/r.grow.distance/main.c

@@ -128,7 +128,7 @@ int main(int argc, char **argv)
     } opt;
     struct
     {
-	struct Flag *m;
+	struct Flag *m, *n;
     } flag;
     const char *in_name;
     const char *dist_name;
@@ -144,6 +144,7 @@ int main(int argc, char **argv)
     DCELL min, max;
     DCELL *out_row;
     double scale = 1.0;
+    int invert;
 
     G_gisinit(argv[0]);
 
@@ -180,6 +181,10 @@ int main(int argc, char **argv)
     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 @@ int main(int argc, char **argv)
     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 @@ int main(int argc, char **argv)
 
 	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);

+ 3 - 0
raster/r.grow.distance/r.grow.distance.html

@@ -6,6 +6,9 @@ value of the nearest non-null cell.
 
 <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>,