[R-sig-Geo] overlay point extraction of pixel radius (3x3 window)

Roger Bivand Roger.Bivand at nhh.no
Wed Dec 10 08:59:28 CET 2008

On Wed, 10 Dec 2008, zack holden wrote:

> Dear list,
> I would like to use points to extract values from underlying grids, 
> modifying my query to return the mean, standard deviation, or other 
> function of the cells adjacent to the center grid cell. I assume this is 
> possible, but I can find no examples of this in previous posts or in the 
> Bivand et al. Applied spatial data analysis book.
> Would anyone be willing to suggest how to do this or better yet, provide 
> some example code?

coordinates(meuse.grid) <- c("x", "y")
gridded(meuse.grid) <- TRUE

# find rook distance (like chess), queen will be
# sqrt(2*(rook^2))
rook <- max(slot(slot(meuse.grid, "grid"), "cellsize"))

# create a list of neighbours for these distance criteria
nb_rook <- dnearneigh(coordinates(meuse.grid), 0, rook)

# only dist is continuous here, and not very interesting
meuse.grid$m_dist <- sapply(nb_rook, function(i) mean(meuse.grid$dist[i]))
spplot(meuse.grid, c("dist", "m_dist"))


> Thanks in advance for any help,
> Zack
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no

More information about the R-sig-Geo mailing list