[GRASS-user] Raster aggregation with r.neighbors

colin mcclean cjm8 at york.ac.uk
Tue Jan 30 05:51:23 EST 2007


Hi Patrick

The r.mapcalc trick might be:
zonemap = col() + (row() - 1) * number of columns

I've always just hardcoded the number of colums...there may another 
trick out there to automate it! col() and row() are internal variables 
in r.mapcalc.

r.resamp.stats sounds good...but I haven't tried it yet either.

Cheers
Colin

Patrick Meyfroidt wrote:
> Thank you for all your advices,
>
> I used also the r.statistics method, but it was very time-consuming to 
> create a base raster map at the desired resolution (I foudn a 
> procedure here in the archive: creating two grids in a spreadsheet 
> editor, one with cell value being the x-coordinate, and the other with 
> cell value being the y-coordinate, and then combine them). And if I 
> want to make tests with other resolutions (say, 6, 7, 8 km instead of 
> 5 km), I need to re-do the same long procedure.
>
> Is there a simple and fast way to create a raster map with unique cell 
> values (one category for each cell)? With some r.mapcalc trick?
>
> (I will switch to r.resamp.stats as soon as I can, but I need to 
> understand this CVS-thing...)
>
> Thank you,
>
> Patrick
>
>
>
>
> At 02:35 27/01/2007, Glynn Clements wrote:
>
>> Patrick Meyfroidt wrote:
>>
>> > I'm working with grass 6.2.1 and I'm looking for a way to aggregate a
>> > raster (downscale the resolution from 1km to 5km by calculating the
>> > average of values over a 5x5 pixels window). It seems that
>> > r.resamp.stats is designed for that, but it is not in version 6.2.1
>> > So I used r.neighbors like that:
>> >
>> >  > g.region res=5000
>> >  > r.neighbors -a input=xxx output=xxx method=average size=5
>> >
>> > In the archive I found that:
>> > http://grass.itc.it/pipermail/grassuser/2002-September/007417.html
>> > but using the -a option seemed to solve the problem of output 
>> resolution.
>> >
>> > Can anyone tell me if this method could be problematic in some way,
>> > or provide less performant results than r.resample.stats?
>>
>> Both the r.statistics and r.neighbors approaches work, but have some
>> drawbacks.
>>
>> r.statistics requires that you first create a suitable base map (with
>> one category for each output cell), and doesn't work well with
>> floating-point data.
>>
>> r.neighbors is significantly slower than r.resamp.stats (e.g. for a
>> 5x5 scaling, it will calculate the aggregate for all 25 cells, then
>> the resampling step discards all but one of them). Also, you are
>> limited to odd window sizes (3x3, 5x5, 7x7 etc).
>>
>> Also, both involve several steps: set region to source resolution,
>> compute aggregate, set region to target resolution, resample.
>>
>> r.resamp.stats does the same thing with a single command, and isn't
>> limited to odd window sizes (or even to a fixed size; it will work
>> correctly where the scale factor isn't an integer).
>>
>> -- 
>> Glynn Clements <glynn at gclements.plus.com>
>
> _______________________________________________
> grassuser mailing list
> grassuser at grass.itc.it
> http://grass.itc.it/mailman/listinfo/grassuser


-- 
----------------------------------------------
Dr Colin McClean
Environment Department
University of York
Heslington
York YO10 5DD
Tel: +44-(0)1904-432995
Fax: +44-(0)1904-432998
http://www.york.ac.uk/environment/
-----------------------------------------------





More information about the grass-user mailing list