[GRASS-user] MAP Calculator mean of eight neighbors to
interpolate 0 value in raster map
Glynn Clements
glynn at gclements.plus.com
Fri Aug 28 18:21:29 EDT 2009
stephen sefick wrote:
> >> This does not quite work for my purposes. The problem is the the 0
> >> values are in a 2 or 3 grid wide seam in between patched raster maps,
> >> so the value is lower than it should be using
> >>
> >> r.mapcalc "benning_dem=if(patch_benning==0,
> >> (patch_benning[-1,-1]+patch_benning[1,-1]+patch_benning[-1,0]+
> >> patch_benning[1,0]+patch_benning[-1,1]+patch_benning[1,1])/6,
> >> patch_benning)"
> >>
> >> any thoughts,
> >
> > Do you want the average of all of the surrounding values, or only the
> > non-zero values?
>
> only the no zero values. I could probably do something like if
> patch_benning[-1,-1]>0 etc., but I don not know how to code the number
> of non-zero numbers in the divisor to get and average.
r.mapcalc "benning_dem = eval( \
m = patch_benning, \
numer = m[-1,-1]+ m[-1,0]+ m[-1,1]+ m[0,-1]+ m[0,1]+ m[1,-1]+ m[1,0]+ m[1,1], \
denom = !m[-1,-1]+!m[-1,0]+!m[-1,1]+!m[0,-1]+!m[0,1]+!m[1,-1]+!m[1,0]+!m[1,1], \
if(m,m,numer/denom))
The "!" (logical "not") operator returns 1 if its operand is zero and
0 otherwise.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list