[GRASS-user] circle surrounding neighbors

Glynn Clements glynn at gclements.plus.com
Tue Jul 31 14:07:35 EDT 2007


Martin Wegmann wrote:

> > I'm unsure as to whether the test should be < or <=. It's currently
> > <=, but that gives "spikes" (single cells) at the four edges. Using <
> > would give "flats", and would always omit the outermost row/column of
> > pixels. Maybe there should be a +0.5 in the distance calculation?
> 
> then the command works like
> 
> r.neighbors -c input=name output=name method=average size=5 
> and the output would be the average of values in a ring of 5x5 around the 
> center pixel, wouldn't it? 

It's a filled circle (disc), not a "ring". The neighbourhood consists
of all cells whose Euclidean distance from the output cell is <=
size/2:

    for (i = 0; i < ncb.nsize; i++)
	for (j = 0; j < ncb.nsize; j++)
	    ncb.mask[i][j] = sqr(i - ncb.dist) + sqr(j - ncb.dist) <= sqr(ncb.dist);

Note: "<=", not "=".

> then I can drop my r.mapcalc script and close one old wish report related to 
> r.le but solved via r.neighbors 
> (http://www.intevation.de/rt/webrt?serial_num=2104&display=History) - thanks 
> a lot!

The diagram in that post suggests a ring rather than a circle.

I suppose I could add a (e.g.) matrix= option to read an
r.mfilter-style matrix from a file

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




More information about the grass-user mailing list