[GRASS-user] making sense of r.reclass.area

Dear GRASS list,

I'm having trouble understanding how to properly use ~r.reclass.area~. It seems to give inconsistent results. I'm using the following MWE to help me figure this out.

Several questions... such as:

Why are the units in hectare instead of m^2?

Why is -c and -d mutually exclusive for "mode=reclass" but not "mode=rmarea"?

Why does mode=rmarea appear to ignore the -d flag

Why does mode=reclass say it cannot find areas <=1 ha, but only if -c is used, and the module never seems to have trouble finding areas of 1 ha otherwise?

Thanks,

  -k.
  
grass72 -c EPSG:3413 ./Gclump.debug
# frink "1 hectare -> m^2" 10,000 m^2
g.region w=0 e=500 s=0 n=500 res=100 -p

debug() { r.out.xyz -i input=$@ | cut -d"|" -f3 | xargs -n5; }

r.mapcalc "foo = if(row() == 2 && ((col() > 1) && (col() < 4)) , 1, null())" --o
r.mapcalc "foo = if(row() == 3 && col() == 4, 1, foo)" --o
r.mapcalc "foo = if(row() == 4 && col() == 2, 1, foo)" --o

debug foo
# * * * * *
# * 1 1 * *
# * * * 1 *
# * 1 * * *
# * * * * *

# RMAREA

# simple run with no args
r.reclass.area input=foo output=o value=1 mode=lesser method=rmarea --o --q && debug o
r.reclass.area -c input=foo output=o value=1 mode=lesser method=rmarea --o --q && debug o
# WANT: include diagonal
r.reclass.area -d input=foo output=o value=1 mode=lesser method=rmarea --o --q && debug o
r.reclass.area -d -c input=foo output=o value=1 mode=lesser method=rmarea --o --q && debug o

# All produce the same output:
# * * * * *
# * 1 1 * *
# * * * * *
# * * * * *
# * * * * *

# RECLASS

r.reclass.area input=foo output=o value=1 mode=lesser method=reclass --o --q && debug o
# GOOD: flags areas <=1. Does not consider diagonal:
# * * * * *
# * * * * *
# * * * 1 *
# * 1 * * *
# * * * * *

r.reclass.area -c input=foo output=o value=1 mode=lesser method=reclass --o --q && debug o
# ERROR: "No areas <= 1.000 hectar

r.reclass.area -d input=foo output=o value=1 mode=lesser method=reclass --o --q && debug o
# Appears to work, only areas <=1 flagged, including diagonal
# * * * * *
# * * * * *
# * * * * *
# * 1 * * *
# * * * * *

r.reclass.area -c -d input=foo output=o value=1 mode=lesser method=reclass --o --q && debug o
# ERROR: flags c and d are mutually exclusive

exit
rm -fR Gclump.debug

Dear All,

I am very sorry to convey this sad news on this list.

A dear friend and an early pioneer of the GRASS team,
David Hastings passed away in the Hospital in Colorado
on Monday 13 November as 11.25am.

David was a member of the GRASS-GIS Interagency Steering
Committee (GIASC) since 1987. I think he was a member till he passed
away, since GIASC was never formally disbanded.

Besides his several other accomplishments, David is also an author of the
Linux " GRASS HOWTO" [1].

David was diagnosed with a serious illness in May, 2016 and could
not recover.

Thanks David for your contributions to GRASS, RIP.

Venka

[1] http://www.tldp.org/HOWTO/GIS-GRASS/
--------
Prof. Venkatesh Raghavan
Osaka City University, Japan

On Mon, Nov 13, 2017 at 11:24 AM, Ken Mankoff <mankoff@gmail.com> wrote:

Dear GRASS list,

I’m having trouble understanding how to properly use ~r.reclass.area~. It seems to give inconsistent results. I’m using the following MWE to help me figure this out.

Several questions… such as:

Why are the units in hectare instead of m^2?

Most probably for historical reasons (the module comes from GRASS 4).

Why is -c and -d mutually exclusive for “mode=reclass” but not “mode=rmarea”?

A bug. They should always be mutually exclusive: either input is already clumped (-c flag), or clumps will be created from the input, considering diagonal neighbours (-d flag).

Why does mode=rmarea appear to ignore the -d flag

The -d flag only has an effect if clumps are created from the input. If the -c flag is set, the input is already clumped and the -d flag has no effect. This is (should be) independent of the mode.

Why does mode=reclass say it cannot find areas <=1 ha, but only if -c is used, and the module never seems to have trouble finding areas of 1 ha otherwise?

Maybe because the input is not clumped?

HTH,

Markus M

Thanks,

-k.

grass72 -c EPSG:3413 ./Gclump.debug

frink “1 hectare → m^2” 10,000 m^2

g.region w=0 e=500 s=0 n=500 res=100 -p

debug() { r.out.xyz -i input=$@ | cut -d"|" -f3 | xargs -n5; }

r.mapcalc “foo = if(row() == 2 && ((col() > 1) && (col() < 4)) , 1, null())” --o
r.mapcalc “foo = if(row() == 3 && col() == 4, 1, foo)” --o
r.mapcalc “foo = if(row() == 4 && col() == 2, 1, foo)” --o

debug foo

* * * * *

* 1 1 * *

* * * 1 *

* 1 * * *

* * * * *

RMAREA

simple run with no args

r.reclass.area input=foo output=o value=1 mode=lesser method=rmarea --o --q && debug o
r.reclass.area -c input=foo output=o value=1 mode=lesser method=rmarea --o --q && debug o

WANT: include diagonal

r.reclass.area -d input=foo output=o value=1 mode=lesser method=rmarea --o --q && debug o
r.reclass.area -d -c input=foo output=o value=1 mode=lesser method=rmarea --o --q && debug o

All produce the same output:

* * * * *

* 1 1 * *

* * * * *

* * * * *

* * * * *

RECLASS

r.reclass.area input=foo output=o value=1 mode=lesser method=reclass --o --q && debug o

GOOD: flags areas <=1. Does not consider diagonal:

* * * * *

* * * * *

* * * 1 *

* 1 * * *

* * * * *

r.reclass.area -c input=foo output=o value=1 mode=lesser method=reclass --o --q && debug o

ERROR: "No areas <= 1.000 hectar

r.reclass.area -d input=foo output=o value=1 mode=lesser method=reclass --o --q && debug o

Appears to work, only areas <=1 flagged, including diagonal

* * * * *

* * * * *

* * * * *

* 1 * * *

* * * * *

r.reclass.area -c -d input=foo output=o value=1 mode=lesser method=reclass --o --q && debug o

ERROR: flags c and d are mutually exclusive

exit
rm -fR Gclump.debug


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Hi Markus,

Thanks for the reply. You're right that unclumped data was part of the problem, but even with that realization and more testing things still don't make sense. Specifically, the diagonal flag doesn't seem to work for rmarea for me, or I'm not understanding how it should work.

I've now clumped my input (and also test this telling r.reclass.area to clump the input by not using the "-c" flag). Text below appears OK in Gmail for me but is best viewed in fixed-width font.

# set up the environment
grass72 -c EPSG:3413 ./Gclump
g.region w=0 e=500 s=0 n=500 res=100 -p
debug() { r.out.xyz -i input=$@ | cut -d"|" -f3 | xargs -n5; }

r.mapcalc "foo = if(row() == 2 && ((col() > 1) && (col() < 4)) , 1, null())" --o
r.mapcalc "foo = if(row() == 3 && col() == 4, 1, foo)" --o
r.mapcalc "foo = if(row() == 4 && col() == 2, 2, foo)" --o

I think I've "clumped" the above, with diagonals, by assigning the 3 cells a value of 1 and the single cell a value of 2. Just to be sure, I'm manually running r.clump 2x:

r.clump input=foo output=foo_c # no diagonals
r.clump -d input=foo output=foo_cd # diagonal

debug foo
debug foo_cd # give the same result
# * * * * *
# * 1 1 * *
# * * * 1 *
# * 2 * * *
# * * * * *

And as expected,

debug foo_c
* * * * *
* 1 1 * *
* * * 2 *
* 3 * * *
* * * * *

On 2017-11-17 at 08:45, Markus Metz <markus.metz.giswork@gmail.com> wrote:

On Mon, Nov 13, 2017 at 11:24 AM, Ken Mankoff <mankoff@gmail.com> wrote:

Why does mode=rmarea appear to ignore the -d flag

The -d flag only has an effect if clumps are created from the input.
If the -c flag is set, the input is already clumped and the -d flag
has no effect. This is (should be) independent of the mode.

OK. So r.reclass.area with foo_cd (diagonal clumped) and the -c flag should remove the small single cell, and retain the 3 cells with 1 diagonal, right?

And this should be the same behavior as if if I pass in foo (unclumped), no "-c" flag, and yes "-d" flag.

r.reclass.area -c input=foo_cd output=o value=1 mode=lesser method=rmarea --o --q && debug o

Everything I run here produces the same result, regardless of which of the three foo* rasters I pass in, or any of the three flag options (NONE, -c, or -d).

* * * * *
* 1 1 * *
* * * * *
* * * * *
* * * * *

  -k.

On Fri, Nov 17, 2017 at 1:40 PM, Ken Mankoff <mankoff@gmail.com> wrote:

Hi Markus,

Thanks for the reply. You’re right that unclumped data was part of the problem, but even with that realization and more testing things still don’t make sense. Specifically, the diagonal flag doesn’t seem to work for rmarea for me, or I’m not understanding how it should work.

OK, I understand now. With method=rmarea, r.reclass converts the raster clumps to vector areas. That single cell in your example below, that either belongs to the larger clump 1 (with -d) or forms a separate clump 2 (without -d) will always be a separate small vector area (topology or not does not matter here) and thus will always be removed independent of the 2-cell clump. The vector approach is thus not working here as expected.

Incidentally I have added a minsize option to r.clump in GRASS 7.4 which should work as expected. Try to use r.clump minsize=X (in number of cells) instead of r.reclass.area method=rmarea mode=lesser.

Markus M

I’ve now clumped my input (and also test this telling r.reclass.area to clump the input by not using the “-c” flag). Text below appears OK in Gmail for me but is best viewed in fixed-width font.

set up the environment

grass72 -c EPSG:3413 ./Gclump
g.region w=0 e=500 s=0 n=500 res=100 -p
debug() { r.out.xyz -i input=$@ | cut -d"|" -f3 | xargs -n5; }

r.mapcalc “foo = if(row() == 2 && ((col() > 1) && (col() < 4)) , 1, null())” --o
r.mapcalc “foo = if(row() == 3 && col() == 4, 1, foo)” --o
r.mapcalc “foo = if(row() == 4 && col() == 2, 2, foo)” --o

I think I’ve “clumped” the above, with diagonals, by assigning the 3 cells a value of 1 and the single cell a value of 2. Just to be sure, I’m manually running r.clump 2x:

r.clump input=foo output=foo_c # no diagonals
r.clump -d input=foo output=foo_cd # diagonal

debug foo
debug foo_cd # give the same result

* * * * *

* 1 1 * *

* * * 1 *

* 2 * * *

* * * * *

And as expected,

debug foo_c


  • 1 1 * *
      • 2 *
  • 3 * * *

On 2017-11-17 at 08:45, Markus Metz <markus.metz.giswork@gmail.com> wrote:

On Mon, Nov 13, 2017 at 11:24 AM, Ken Mankoff <mankoff@gmail.com> wrote:

Why does mode=rmarea appear to ignore the -d flag

The -d flag only has an effect if clumps are created from the input.
If the -c flag is set, the input is already clumped and the -d flag
has no effect. This is (should be) independent of the mode.

OK. So r.reclass.area with foo_cd (diagonal clumped) and the -c flag should remove the small single cell, and retain the 3 cells with 1 diagonal, right?

And this should be the same behavior as if if I pass in foo (unclumped), no “-c” flag, and yes “-d” flag.

r.reclass.area -c input=foo_cd output=o value=1 mode=lesser method=rmarea --o --q && debug o

Everything I run here produces the same result, regardless of which of the three foo* rasters I pass in, or any of the three flag options (NONE, -c, or -d).


  • 1 1 * *



-k.

Hi Markus,

On 2017-11-17 at 14:09, Markus Metz <markus.metz.giswork@gmail.com> wrote:

OK, I understand now. With method=rmarea, r.reclass converts the
raster clumps to vector areas. That single cell in your example below,
that either belongs to the larger clump 1 (with -d) or forms a
separate clump 2 (without -d) will always be a separate small vector
area (topology or not does not matter here) and thus will always be
removed independent of the 2-cell clump. The vector approach is thus
not working here as expected.

Thanks for looking into this and explaining. I'll open a documentation bug on Trac.

Incidentally I have added a minsize option to r.clump in GRASS 7.4 which
should work as expected. Try to use r.clump minsize=X (in number of cells)
instead of r.reclass.area method=rmarea mode=lesser.

Between this and mapcalc area() function in 7.3 I need to find a way use more cutting-edge GRASS versions than 7.2.2 even though I'm on OS X.

  -k.