[GRASS-dev] Re: r.neighbors modification

Glynn Clements glynn at gclements.plus.com
Tue Nov 28 18:27:21 EST 2006

Martin Wegmann wrote:

> I wrote a short neighbourhood ring analysis for average and 
> variance analysis (currently only up to 11x11 but I will add rings up to 
> 21x21).
> Hamish advice how to improve a script (v.cellstats threat) is partly 
> incorporated but I am grateful for any further suggestions how to improve this 
> script.

Average can be computed using r.mfilter; except, that it needs to be
modified to use floating-point.

Variance could be computed using two passes of r.mfilter and two of
r.mapcalc, although that algorithm is less stable in the case of very
small variance relative to the mean (cf historical r.univar.sh

Apart from that, I suggest generating the r.mapcalc expression using
awk, e.g.:

	# expects $size to be the radius of the ring
	awk -vsize=$size -vinf=$GIS_OPT_input -voutf=$GIS_OPT_output \
	print outf" = (0\\" 
	for (i=-size; i<size; i++) {
	print "+"inf"["(-size)","(-i)"]\\" ;
	print "+"inf"["( size)","( i)"]\\" ;
	print "+"inf"["( i)","(-size)"]\\" ;
	print "+"inf"["(-i)","( size)"]\\" ;
	print ")/(8*size)"
	}' < /dev/null | r.mapcalc

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-dev mailing list