[GRASS-user] Downscaling and aggregating raster categories/classes

Hi list.

I am trying to perform the following:

A classified map "A" of 25m pix res. has two main categories B and C.
Downscaling the map to 50m (map "B") results in pixels which correspond to 4
* 25m (original pixels).

Given the region extent is aligned, three possibilities may occur (near the
borders between categories B=11 and C=22) in terms of abundance/coverage in
the resampled map:

1. B = C <-- Mixed (M)
____
|B|B|
|-----|
|C|C|
-------

2. B > C

|B|B|
|-----|
|C|B|
-------

3. B < C

|B|C|
|-----|
|C|C|
-------

The new "categorisation" scheme can be expressed as (in r.mapcalc -- pseudo-
code)

1) if( count(B) > count(C), B)

2) if( count(C) > count(B), C)

3) if( count(B) = count(C), M )

The r.resamp.stats module seems to fit most aggregation tasks. In this
particular case it could be the method=mode. But,

1) the output is a DCELL map! I can understand why it is deriving floating
point values. Is a simple r.mapcalc round() operation enough to get close to
the desired values? Would an "-i" switch (as in integer) make sense here?

2) What happens when "method=mode" and "count(B) == count(C)", as described
above?

I know that something else can do it -- e.g. something like summing-up and
recoding later. That is however more steps. Even, method=sum also outputs
DCELL map(s).

Any recommendations? Can't this be done i a single step in grass (2 by 2
window)?

I've been reading the old and very good tutorial on r.mapcalc (thank you
Markus for pointing to it). Is it a better solution to construct this in
r.mapcalc using the map[r,c] operator?

Two essential questions:

- how to get a 2 by 2 *moving* window in r.mapcalc?
- how to replicate a "count()" method in r.mapcalc?

Thanks, Nikos

Nikos Alexandris wrote:
..

The r.resamp.stats module seems to fit most aggregation tasks. In this
particular case it could be the method=mode. But,

1) the output is a DCELL map! I can understand why it is deriving floating
point values. Is a simple r.mapcalc round() operation enough to get close
to the desired values?

make that r.mapcalc int()

Would an "-i" switch (as in integer) make sense
here?

The question still remains.

Thanks, Nikos

For whom it may be of interest!

Nikos Alexandris wrote:

I am trying to perform the following:

A classified map "A" of 25m pix res. has two main categories B and C.
Downscaling the map to 50m (map "B") results in pixels which correspond to
4 * 25m (original pixels).

Given the region extent is aligned, three possibilities may occur (near the
borders between categories B=11 and C=22) in terms of abundance/coverage in
the resampled map:

1. B = C <-- Mixed (M)
____

|B|B|
|-----|
|C|C|

-------

2. B > C

|B|B|
|-----|
|C|B|

-------

3. B < C

|B|C|
|-----|
|C|C|

-------

..

I did:

#1
r.resamp.stats input=A output=B method=sum # map A has two cats: 11 & 12

#2
r.mapcalc "B_int = int( B )"

# 3
r.recode in=B_int out=B_int_recoded rules=RecodingRules

where RecodingRules contains:

44:44:11:11
45:45:11:11
46:46:13:13
47:47:12:12
48:48:12:12

where class B = 11, class C = 12 and a (new) Mixed class is M=13.

It would be nice to get this in one step :slight_smile:

Best, Nikos

On Wednesday 27 of February 2013 22:37:58 Nikos Alexandris wrote:

I did:

(1st)

g.region zoom=A # this is a 25m pix-res map
g.region res=50 -pa

(then the rest!)

#1
r.resamp.stats input=A output=B method=sum # map A has two cats: 11 & 12

#2
r.mapcalc "B_int = int( B )"

# 3
r.recode in=B_int out=B_int_recoded rules=RecodingRules

where RecodingRules contains:

44:44:11:11
45:45:11:11
46:46:13:13
47:47:12:12
48:48:12:12

where class B = 11, class C = 12 and a (new) Mixed class is M=13.

Nikos