Opened 10 years ago

Closed 10 years ago

#2400 closed enhancement (fixed)

r.reclass.area: add option to use r.clump's -d flag

Reported by: peifer Owned by: grass-dev@…
Priority: normal Milestone: 7.0.0
Component: Python Version: svn-trunk
Keywords: r.reclass.area Cc:
CPU: Unspecified Platform: All

Description

See above

Attachments (1)

r.reclass.area.patch (1.6 KB ) - added by peifer 10 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 by hamish, 10 years ago

Keywords: r.reclass.area added

what would this -d flag do?

comment:2 by peifer, 10 years ago

Summary: r.reclass.area: add option to use -d flagr.reclass.area: add option to use r.clump's -d flag

comment:3 by neteler, 10 years ago

Milestone: 7.0.0
Platform: UnspecifiedAll

In r.clump it is:

-d
    Clump also diagonal cells
    Clumps are also traced along diagonal neighboring cells

At time there is in r.reclass.area

-c
    Input map is clumped

How would you describe the potential -d flag here (and perhaps modify the -c description)?

comment:4 by peifer, 10 years ago

Maybe I am just plain stupid, but my simple idea was that r.reclass.area should have an option to use r.clump's rather recently introduced -d flag. Only in cases where the map is NOT pre-clumped, of course. Updated descriptions could be:

-c

Input map is already clumped. Flags -c and -d are mutually exclusive.

-d

Area size of generated clumps includes diagonally neighboring cells. Flags -d and -c are mutually exclusive.

The above enhancement would avoid that one has to pre-clump separately, in case one is interested in diagonal neighbors.

in reply to:  4 ; comment:5 by neteler, 10 years ago

Your idea is pretty clear! We just need to find the least confusing flag descriptions, that's all...

The part of "Flags -c and -d are mutually exclusive" will go into the Python script itself.

-c Input map is already clumped

-d Area size of generated clumps includes diagonally neighboring cells

I am not sure if the difference between -c and -d is already obvious. And I thought that the proposed -d should correspond to that of r.clump in its behaviour?

in reply to:  5 comment:6 by peifer, 10 years ago

Replying to neteler:

I am not sure if the difference between -c and -d is already obvious. And I thought that the proposed -d should correspond to that of r.clump in its behaviour?

Of course. My wording was bad. My thought was that people using r.reclass.area focus more on the size limit. For them, the clumping is only and intermediate step towards applying an area size filter. Why not blindly copying the text from r.clump (which is a bit repetitive in itself, though):

-d  Clump also diagonal cells
    Clumps are also traced along diagonal neighboring cells

PS, and somewhat beyond the enhancement request in this ticket: What would be really neat for experimenting with different area sizes: r.clump would write the area size in px into the category labels and r.reclass would be able to use the size values from there. One would clump once only and could check the effects of various rules (by reclassifying unwanted size classes to NULL).

comment:7 by peifer, 10 years ago

Resolution: worksforme
Status: newclosed

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)

comment:8 by neteler, 10 years ago

Resolution: worksforme
Status: closedreopened

Please add the diff as attachment to the ticket. It may then remain open unless it was updated in SVN.

by peifer, 10 years ago

Attachment: r.reclass.area.patch added

comment:9 by peifer, 10 years ago

Here you are.

in reply to:  9 ; comment:10 by annakrat, 10 years ago

Replying to peifer:

Here you are.

I committed it in r61829. Needs testing of course.

I was wondering, should the example on r.reclass.area man page include the -c flag? The zipcodes are already clumped, or?

in reply to:  10 comment:11 by neteler, 10 years ago

Replying to annakrat:

I was wondering, should the example on r.reclass.area man page include the -c flag? The zipcodes are already clumped, or?

The codes should be (the associated names not necessarily).

in reply to:  10 comment:12 by peifer, 10 years ago

Replying to annakrat:

The zipcodes are already clumped, or?

It doesn't look like: zipcodes has 13 distinct cat values. r.clump generates 16 clumps and r.clump -d generates 14 clumps.

Maybe zipcodes isn't a good example map for r.reclass.area in the first place, because when following the man page: some area of zip code 27606 is lost during the clumping (without the innocent user being aware of this risk, I would assume).

|27606|RALEIGH. . . . . . . . . .|  6626.420| # Size in ha in original zipcodes map
|27606|RALEIGH. . . . . . . . . .|  6626.410| # 1 px = 100m2 = 0.01 ha lost in zipcodes_larger2000ha

comment:13 by peifer, 10 years ago

Resolution: fixed
Status: reopenedclosed

Works as expected in trunk. I will close the ticket.

Note: See TracTickets for help on using tickets.