[GRASS-SVN] r69110 - grass/trunk/scripts/r.grow
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 9 01:23:55 PDT 2016
Author: mmetz
Date: 2016-08-09 01:23:55 -0700 (Tue, 09 Aug 2016)
New Revision: 69110
Modified:
grass/trunk/scripts/r.grow/r.grow.html
grass/trunk/scripts/r.grow/r.grow.py
Log:
r.grow: +shrink
Modified: grass/trunk/scripts/r.grow/r.grow.html
===================================================================
--- grass/trunk/scripts/r.grow/r.grow.html 2016-08-09 03:12:10 UTC (rev 69109)
+++ grass/trunk/scripts/r.grow/r.grow.html 2016-08-09 08:23:55 UTC (rev 69110)
@@ -8,6 +8,10 @@
option of preserving the original cells (similar to combining
<em>r.buffer</em> and <em>r.patch</em>).
+<p>
+If <b>radius</b> is negative,<em>r.grow</em> shrinks areas by removing
+cells around the perimeters of all areas.
+
<h2>NOTES</h2>
The user has the option of specifying three different metrics which
control the geometry in which grown cells are created, (controlled by
@@ -55,9 +59,16 @@
<div class="code"><pre>
g.region raster=lakes -p
-r.grow input=lakes output=lakes_grown_50m radius=10
+r.grow input=lakes output=lakes_grown_100m radius=10
</pre></div>
+Shrinking instead of growing:
+
+<div class="code"><pre>
+r.grow input=lakes output=lakes_shrunk_100m radius=-10
+</pre></div>
+
+
<h2>SEE ALSO</h2>
<em>
Modified: grass/trunk/scripts/r.grow/r.grow.py
===================================================================
--- grass/trunk/scripts/r.grow/r.grow.py 2016-08-09 03:12:10 UTC (rev 69109)
+++ grass/trunk/scripts/r.grow/r.grow.py 2016-08-09 08:23:55 UTC (rev 69110)
@@ -90,8 +90,13 @@
tmp = str(os.getpid())
temp_dist = "r.grow.tmp.%s.dist" % tmp
+
+ shrink = False
+ if radius < 0.0:
+ shrink = True
+ radius = -radius
- if new == '':
+ if new == '' and shrink == False:
temp_val = "r.grow.tmp.%s.val" % tmp
new = temp_val
else:
@@ -113,17 +118,29 @@
if not grass.find_file(input)['file']:
grass.fatal(_("Raster map <%s> not found") % input)
- try:
- grass.run_command('r.grow.distance', input=input, metric=metric,
- distance=temp_dist, value=temp_val)
- except CalledModuleError:
- grass.fatal(_("Growing failed. Removing temporary maps."))
+ if shrink == False:
+ try:
+ grass.run_command('r.grow.distance', input=input, metric=metric,
+ distance=temp_dist, value=temp_val)
+ except CalledModuleError:
+ grass.fatal(_("Growing failed. Removing temporary maps."))
- grass.mapcalc(
- "$output = if(!isnull($input),$old,if($dist < $radius,$new,null()))",
- output=output, input=input, radius=radius,
- old=old, new=new, dist=temp_dist)
+ grass.mapcalc(
+ "$output = if(!isnull($input),$old,if($dist < $radius,$new,null()))",
+ output=output, input=input, radius=radius,
+ old=old, new=new, dist=temp_dist)
+ else:
+ # shrink
+ try:
+ grass.run_command('r.grow.distance', input=input, metric=metric,
+ distance=temp_dist, value=temp_val, flags='n')
+ except CalledModuleError:
+ grass.fatal(_("Shrinking failed. Removing temporary maps."))
+ grass.mapcalc(
+ "$output = if($dist < $radius,null(),$old)",
+ output=output, radius=radius, old=old, dist=temp_dist)
+
grass.run_command('r.colors', map=output, raster=input)
# write cmd history:
More information about the grass-commit
mailing list