Opened 5 years ago

Closed 5 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 5 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 5 years ago by hamish

Keywords: r.reclass.area added

what would this -d flag do?

comment:2 Changed 5 years ago by peifer

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

comment:3 Changed 5 years ago by neteler

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 Changed 5 years ago by peifer

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.

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

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?

comment:6 in reply to:  5 Changed 5 years ago by peifer

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 Changed 5 years ago by peifer

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 Changed 5 years ago by neteler

Resolution: worksforme
Status: closedreopened

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

Changed 5 years ago by peifer

Attachment: r.reclass.area.patch added

comment:9 Changed 5 years ago by peifer

Here you are.

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

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?

comment:11 in reply to:  10 Changed 5 years ago by neteler

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).

comment:12 in reply to:  10 Changed 5 years ago by peifer

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 Changed 5 years ago by peifer

Resolution: fixed
Status: reopenedclosed

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

Note: See TracTickets for help on using tickets.