[GRASS-SVN] r59735 - grass/trunk/raster/r.grow
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Apr 15 03:42:40 PDT 2014
Author: mmetz
Date: 2014-04-15 03:42:40 -0700 (Tue, 15 Apr 2014)
New Revision: 59735
Modified:
grass/trunk/raster/r.grow/main.c
grass/trunk/raster/r.grow/r.grow.html
Log:
r.grow: shrink for negative radius
Modified: grass/trunk/raster/r.grow/main.c
===================================================================
--- grass/trunk/raster/r.grow/main.c 2014-04-15 10:13:10 UTC (rev 59734)
+++ grass/trunk/raster/r.grow/main.c 2014-04-15 10:42:40 UTC (rev 59735)
@@ -24,6 +24,9 @@
#include <grass/raster.h>
#include <grass/glocale.h>
+#ifdef MAX
+#undef MAX
+#endif
#define MAX(a, b) ((a) > (b) ? (a) : (b))
static int size;
@@ -115,6 +118,7 @@
DCELL *out_row;
int nrows, row;
int ncols, col;
+ int shrink;
G_gisinit(argv[0]);
@@ -163,7 +167,13 @@
in_name = opt.in->answer;
out_name = opt.out->answer;
+ shrink = 0;
+
radius = atof(opt.rad->answer);
+ if (radius < 0) {
+ shrink = 1;
+ radius = -radius;
+ }
if (opt.old->answer)
oldval = atoi(opt.old->answer);
@@ -227,38 +237,66 @@
for (col = 0; col < ncols; col++) {
DCELL *c = &in_rows[size][col];
- if (!Rast_is_d_null_value(c)) {
- if (opt.old->answer) {
- if (oldval < 0)
+ if (shrink) {
+ if (Rast_is_d_null_value(c)) {
+ Rast_set_d_null_value(&out_row[col], 1);
+ continue;
+ }
+
+ for (i = 0; i < count; i++) {
+ int dx = neighbors[i][0];
+ int dy = neighbors[i][1];
+ int x = col + dx;
+ int y = row + dy;
+
+ if (x < 0 || x >= ncols || y < 0 || y >= nrows)
+ continue;
+
+ c = &in_rows[size + dy][x];
+
+ if (Rast_is_d_null_value(c)) {
Rast_set_d_null_value(&out_row[col], 1);
- else
- out_row[col] = oldval;
+ break;
+ }
}
- else
+
+ if (i == count)
out_row[col] = *c;
-
- continue;
}
+ else {
+ if (!Rast_is_d_null_value(c)) {
+ if (opt.old->answer) {
+ if (oldval < 0)
+ Rast_set_d_null_value(&out_row[col], 1);
+ else
+ out_row[col] = oldval;
+ }
+ else
+ out_row[col] = *c;
- for (i = 0; i < count; i++) {
- int dx = neighbors[i][0];
- int dy = neighbors[i][1];
- int x = col + dx;
- int y = row + dy;
-
- if (x < 0 || x >= ncols || y < 0 || y >= nrows)
continue;
+ }
- c = &in_rows[size + dy][x];
+ for (i = 0; i < count; i++) {
+ int dx = neighbors[i][0];
+ int dy = neighbors[i][1];
+ int x = col + dx;
+ int y = row + dy;
- if (!Rast_is_d_null_value(c)) {
- out_row[col] = opt.new->answer ? newval : *c;
- break;
+ if (x < 0 || x >= ncols || y < 0 || y >= nrows)
+ continue;
+
+ c = &in_rows[size + dy][x];
+
+ if (!Rast_is_d_null_value(c)) {
+ out_row[col] = opt.new->answer ? newval : *c;
+ break;
+ }
}
+
+ if (i == count)
+ Rast_set_d_null_value(&out_row[col], 1);
}
-
- if (i == count)
- Rast_set_d_null_value(&out_row[col], 1);
}
Rast_put_d_row(out_fd, out_row);
Modified: grass/trunk/raster/r.grow/r.grow.html
===================================================================
--- grass/trunk/raster/r.grow/r.grow.html 2014-04-15 10:13:10 UTC (rev 59734)
+++ grass/trunk/raster/r.grow/r.grow.html 2014-04-15 10:42:40 UTC (rev 59735)
@@ -7,6 +7,8 @@
parameter), or like <em>r.buffer</em>, but with the
option of preserving the original cells (similar to combining
<em>r.buffer</em> and <em>r.patch</em>).
+<p>
+A negative <b>radius</b> shrinks inwards instead of growing outwards.
<h2>NOTES</h2>
@@ -56,18 +58,13 @@
<h2>EXAMPLE</h2>
-You can shrink inwards by preparing an inverse map first, and then
-inverting the resulting grown map. For example:
+You can shrink inwards by using a negative radius. For example:
<div class="code"><pre>
-# Spearfish sample dataset
+# North Carolina sample dataset
-MAP=fields
-g.region rast=$MAP
-r.mapcalc "inverse = if(isnull($MAP), 1, null())"
-r.grow in=inverse out=inverse.grown
-r.mapcalc "$MAP.shrunken = if(isnull(inverse.grown), $MAP, null())"
-r.colors $MAP.shrunken rast=$MAP
-g.remove inverse,inverse.grown
+g.region rast=lakes
+r.grow in=lakes out=lakes.shrunken radius=-2.01
+r.colors lakes.shrunken rast=lakes
</pre></div>
More information about the grass-commit
mailing list