Skip to content
Prev 4424 / 29559 Next

subsetting

Tomislav Hengl wrote:
I do think so: overlay in sp is your friend:

library(sp)
data(meuse.grid)
gridded(meuse.grid) = ~x+y
grd = spsample(meuse.grid, n = 100, type = "regular")
image(meuse.grid["dist"])
points(grd, pch = 3)

gridded(grd)= TRUE
overlay(meuse.grid, grd)
grddf = SpatialPixelsDataFrame(grd, as(meuse.grid, 
"data.frame")[overlay(meuse.grid, grd),])
image(grddf["dist"])
points(as(grd, "SpatialPoints"), pch = 3)

Note that there is only a single code line that does the resample. If 
anyone has suggestions for a cleaner or simpler interface, or a function 
or method resample, please let me know.

This of course does not do any interpolation; I consider that a 
different chapter (and package). I cannot see how spTransform could help 
here.When warping grids, you'd have to revert them first into polygons 
and spTransform them, to conserve the non-square grid cells resulting.
--
Edzer