[GRASS-SVN] r59376 - grass/trunk/scripts/r.reclass.area

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 26 09:00:14 PDT 2014


Author: lucadelu
Date: 2014-03-26 09:00:13 -0700 (Wed, 26 Mar 2014)
New Revision: 59376

Modified:
   grass/trunk/scripts/r.reclass.area/r.reclass.area.html
   grass/trunk/scripts/r.reclass.area/r.reclass.area.py
Log:
r.reclass.area: apply patch from ticket #2090; PEP8 cleaning; update documentation with new flag

Modified: grass/trunk/scripts/r.reclass.area/r.reclass.area.html
===================================================================
--- grass/trunk/scripts/r.reclass.area/r.reclass.area.html	2014-03-26 15:53:41 UTC (rev 59375)
+++ grass/trunk/scripts/r.reclass.area/r.reclass.area.html	2014-03-26 16:00:13 UTC (rev 59376)
@@ -2,6 +2,9 @@
 
 <em>r.reclass.area</em> reclasses a raster map greater or
 less than a user specified area size (in hectares).
+<p>
+If the <em>-c</em> flag is used, <em>r.reclass.area</em> will skip the creation
+of a clumped raster and assume that the input raster is already clumped.
 
 <h2>EXAMPLE</h2>
 
@@ -17,9 +20,11 @@
 
 <h2>SEE ALSO</h2>
 
-<em><a href="r.reclass.html">r.reclass</a></em><br>
-<em><a href="r.clump.html">r.clump</a></em><br>
-<em><a href="r.stats.html">r.stats</a></em><br>
+<em>
+<a href="r.reclass.html">r.reclass</a>,
+<a href="r.clump.html">r.clump</a>,
+<a href="r.stats.html">r.stats</a>
+</em>
 
 <h2>AUTHORS</h2>
 

Modified: grass/trunk/scripts/r.reclass.area/r.reclass.area.py
===================================================================
--- grass/trunk/scripts/r.reclass.area/r.reclass.area.py	2014-03-26 15:53:41 UTC (rev 59375)
+++ grass/trunk/scripts/r.reclass.area/r.reclass.area.py	2014-03-26 16:00:13 UTC (rev 59376)
@@ -13,6 +13,7 @@
 #               for details.
 #
 #############################################################################
+# 10/2013: added option to use a pre-clumped input map (Eric Goddard)
 # 8/2012: added fp maps support, cleanup, removed tabs AK
 # 3/2007: added label support MN
 # 3/2004: added parser support MN
@@ -48,6 +49,11 @@
 #% guisection: Area
 #%end
 
+#%flag
+#% key: c
+#% description: Input map is clumped
+#%end
+
 import sys
 import os
 import atexit
@@ -55,14 +61,16 @@
 
 TMPRAST = []
 
+
 def main():
     infile = options['input']
     lesser = options['lesser']
     greater = options['greater']
     outfile = options['output']
+    clumped = flags['c']
 
-    s = grass.read_command("g.region", flags = 'p')
-    kv = grass.parse_key_val(s, sep = ':')
+    s = grass.read_command("g.region", flags='p')
+    kv = grass.parse_key_val(s, sep=':')
     s = kv['projection'].strip().split()
     if s == '0':
         grass.fatal(_("xy-locations are not supported"))
@@ -80,29 +88,36 @@
     if not grass.find_file(infile)['name']:
         grass.fatal(_("Raster map <%s> not found") % infile)
 
-    clumpfile = "%s.clump.%s" % (infile.split('@')[0], outfile)
-    TMPRAST.append(clumpfile)
+    if clumped:
+        clumpfile = infile
+    else:
+        clumpfile = "%s.clump.%s" % (infile.split('@')[0], outfile)
+        TMPRAST.append(clumpfile)
 
-    if not grass.overwrite():
-        if grass.find_file(clumpfile)['name']:
-            grass.fatal(_("Temporary raster map <%s> exists") % clumpfile)
+        if not grass.overwrite():
+            if grass.find_file(clumpfile)['name']:
+                grass.fatal(_("Temporary raster map <%s> exists") % clumpfile)
 
-    grass.message(_("Generating a clumped raster file ..."))
-    grass.run_command('r.clump', input = infile, output = clumpfile)
+        grass.message(_("Generating a clumped raster file ..."))
+        grass.run_command('r.clump', input=infile, output=clumpfile)
 
     if lesser:
-        grass.message(_("Generating a reclass map with area size less than or equal to %f hectares...") % limit)
+        grass.message(_("Generating a reclass map with area size less than " \
+                        "or equal to %f hectares...") % limit)
     else:
-        grass.message(_("Generating a reclass map with area size greater than or equal to %f hectares...") % limit)
+        grass.message(_("Generating a reclass map with area size greater " \
+                        "than or equal to %f hectares...") % limit)
 
     recfile = outfile + '.recl'
     TMPRAST.append(recfile)
 
-    flags = 'aln'
+    sflags = 'aln'
     if grass.raster_info(infile)['datatype'] in ('FCELL', 'DCELL'):
-        flags += 'i'
-    p1 = grass.pipe_command('r.stats', flags = flags, input = (clumpfile, infile), sep = ';')
-    p2 = grass.feed_command('r.reclass', input = clumpfile, output = recfile, rules = '-')
+        sflags += 'i'
+    p1 = grass.pipe_command('r.stats', flags=sflags, input=(clumpfile, infile),
+                            sep=';')
+    p2 = grass.feed_command('r.reclass', input=clumpfile, output=recfile,
+                            rules='-')
     rules = ''
     for line in p1.stdout:
         f = line.rstrip(os.linesep).split(';')
@@ -122,21 +137,22 @@
     p2.wait()
     if p2.returncode != 0:
         if lesser:
-            grass.fatal(_("No areas of size less than or equal to %f hectares found.") % limit)
+            grass.fatal(_("No areas of size less than or equal to %f " \
+                          "hectares found.") % limit)
         else:
-            grass.fatal(_("No areas of size greater than or equal to %f hectares found.") % limit)
+            grass.fatal(_("No areas of size greater than or equal to %f " \
+                          "hectares found.") % limit)
 
     grass.message(_("Generating output raster map <%s>...") % outfile)
 
-    grass.mapcalc("$outfile = $recfile", outfile = outfile, recfile = recfile)
+    grass.mapcalc("$outfile = $recfile", outfile=outfile, recfile=recfile)
 
+
 def cleanup():
     """!Delete temporary maps"""
-    TMPRAST.reverse() # reclassed map first
+    TMPRAST.reverse()  # reclassed map first
     for rast in TMPRAST:
-        grass.run_command("g.remove",
-                          rast = rast,
-                          quiet = True)
+        grass.run_command("g.remove", rast=rast, quiet=True)
 
 if __name__ == "__main__":
     options, flags = grass.parser()



More information about the grass-commit mailing list