[GRASS-dev] [GRASS GIS] #2400: r.reclass.area: add option to use r.clump's -d flag

GRASS GIS trac at osgeo.org
Sun Sep 7 06:21:42 PDT 2014


#2400: r.reclass.area: add option to use r.clump's -d flag
--------------------------+-------------------------------------------------
  Reporter:  peifer       |       Owner:  grass-dev@…              
      Type:  enhancement  |      Status:  closed                   
  Priority:  normal       |   Milestone:  7.0.0                    
 Component:  Python       |     Version:  svn-trunk                
Resolution:  worksforme   |    Keywords:  r.reclass.area           
  Platform:  All          |         Cpu:  Unspecified              
--------------------------+-------------------------------------------------
Changes (by peifer):

  * status:  new => closed
  * resolution:  => worksforme


Comment:

 I'm no Python programmer or anything, but dared to do the below changes in
 the current source code. My local r.reclass.area now works as expected, so
 I will close this ticket.

 {{{
 --- r.reclass.area.org  2014-09-07 14:56:32.000000000 +0200
 +++ r.reclass.area      2014-09-07 15:06:12.000000000 +0200
 @@ -54,6 +54,11 @@
  #% description: Input map is clumped
  #%end

 +#%flag
 +#% key: d
 +#% description: Clumps include diagonal neighbors
 +#%end
 +
  import sys
  import os
  import atexit
 @@ -68,6 +73,7 @@
      greater = options['greater']
      outfile = options['output']
      clumped = flags['c']
 +    diagonal = flags['d']

      s = grass.read_command("g.region", flags='p')
      kv = grass.parse_key_val(s, sep=':')
 @@ -88,6 +94,9 @@
      if not grass.find_file(infile)['name']:
          grass.fatal(_("Raster map <%s> not found") % infile)

 +    if clumped and diagonal:
 +        grass.fatal(_("flags c and d are mutually exclusive"))
 +
      if clumped:
          clumpfile = infile
      else:
 @@ -98,9 +107,14 @@
              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)

 +        if diagonal:
 +            grass.message(_("Generating a clumped raster file including
 diagonal neighbors..."))
 +            grass.run_command('r.clump', flags='d', input=infile,
 output=clumpfile)
 +        else:
 +            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)
 }}}

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/2400#comment:7>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list