[R-sig-Geo] Function to smooth grids using n x n window moving average (low-pass filter)

Paul Hiemstra p.hiemstra at geo.uu.nl
Mon Feb 21 14:55:54 CET 2011


On 01/19/2011 05:56 PM, piero campa wrote:
> Very quick method Paul,
> I tried on my own by simple pixel by pixel computing and the result is much
> slower.
> Good work.
>
> Anyway I was trying to understand how to yield a small modification to your
> code:
> having a SpatiaGridDataFrame with NA holes, I noticed that the borderline
> pixels turn to NA too (and that's because x + NA = NA in R by default),
> letting theholes grow proportionally to the kernel size (just like the
> border pixels in a fullgrid data frame).
>
> I was trying to do add the ability to ignore NAs (just like it's in the sum
> method with na.rm = TRUE).
> I can't find the way however.
>
> Thank for any suggestion !
> Cheers,
> Piero
>    
Hi Piero,

It can probably be done relatively fast, but I would try and use the 
functions Robert Hijmans suggested. They are much more generic than my 
approach and probably just as fast, or even faster.

cheers,
Paul

-- 
Paul Hiemstra, MSc
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 253 5773
http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

currently @ KNMI
paul.hiemstra_AT_knmi.nl



More information about the R-sig-Geo mailing list