[GRASS-user] Moving windows on raster categorical map

Glynn Clements glynn at gclements.plus.com
Thu Nov 6 00:36:25 EST 2008


Milton Cezar Ribeiro wrote:

> I have a categorical raster map with 5 classes.
> Now I need to estimate some stats using different-sized windows
> like 3x3, 5x5..25x25. The stats the I would like
> to compute is to count the number of classes on
> the windows, to estimate the percentage of an
> class of interest (like class 4, for example),
> and other stats that could be computed using
> the pixels inside the windows.
> 
> As you can see, the size of windows will varying,
> so as final solution I think to include the solution
> on a "for XX in ()... done" looping.

r.neighbors, possibly in conjunction with r.mapcalc and/or r.reclass.

"r.neighbors method=diversity" will count the number of distinct
categories within the window.

"r.neighbors method=average" will calculate the mean of the values
within the window. If you generate a reclass map so that the category
of interest maps to one and the other categories map to zero, this
will calculate the proportion of cells which have the desired
category.

If you want something which can't be computed by r.neighbors in
conjunction with some pre- or post-processing steps, you can either
modify r.neighbors, or produce something equivalent using r.mapcalc.

There is no specific limit to the complexity of an r.mapcalc script,
although complex scripts can be quite slow. OTOH, r.neighbors also
gets slower in proportion to the number of cells in the neighbourhood
window.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list