[GRASS-user] Raster aggregation with r.neighbors

Glynn Clements glynn at gclements.plus.com
Tue Jan 30 06:06:17 EST 2007


Patrick Meyfroidt wrote:

> 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?

Two options spring to mind:

1. Diagonal numbering:

	r.mapcalc 'basemap=eval(r=row(),c=col(),n=r+c-1,r+n*(n-1)/2)'

2. Raster numbering:

	eval `g.region -g`
	r.mapcalc "basemap=(row()-1)*$cols+col()"

Note the use of double quotes in the second case, to allow $cols to be
expanded by the shell.

Whilst #1 is simpler, it is slightly more sparse (the highest category
will be roughly twice that for #2), and so will overflow the range of
a signed integer earlier (you are limited to ~33000 rows/cols for #1
vs ~46000 for #2).

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




More information about the grass-user mailing list