[GRASS-dev] r.neighbors modification

Glynn Clements glynn at gclements.plus.com
Tue Nov 14 23:44:42 EST 2006


Martin Wegmann wrote:

> I am looking for a way to  compute r.neighbors for a ring only and not for the 
> whole 5x5, 7x7 etc. moving window. 
> It is something like a 7x7 windows but minus the values in the 5x5 windows.
> 
> traditional way:
> 
>  a a a a a 
>  a b b b a 
>  a b x b a 
>  a b b b a 
>  a a a a a 
> 
> ring analysis:
> 
>  a a a a a 
>  a         a 
>  a    x    a 
>  a         a 
>  a a a a a 

I'm guessing that should be:

>  a a a a a 
>  a       a 
>  a   x   a 
>  a       a 
>  a a a a a 

> 
> I think there is no post-r.neighbors way to compute statistics in such 
> a "ring",

It depends upon the aggregate. Some of them could be computed with a
combination of r.neighbors and r.mapcalc commands.

They could all be done using r.mapcalc, but some of them might require
excessively complex expressions (at a minimum, they would all involve
16 map[r,c] terms). r.mapcalc has n-ary min, max, median and mode; sum
and mean are fairly easy to write (you would probably want to process
the nulls separately to simplify the expressions), variance and stddev
aren't hard but would be somewhat more verbose.

Of course, the expressions get longer as the window size increases,
and you would need a separate expression for each size (although you
could probably generate it from a script).

> hence I or somebody else has to modify the source code. I am 
> willing to learn some more C programming, but definitely need some help to 
> get started. 

I'm not sure it's worth modifying r.neighbors for this specific case
(it might be worth you modifying your version, but not us shipping a
modified version). More generally useful would be to allow the
neighbourhood set to be read from a file, similar to r.mfilter (or
even just have a list of offsets as an optional argument).

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




More information about the grass-dev mailing list