[R-sig-Geo] grid and spatial selection

rundel rundel at gmail.com
Sat Jul 24 05:22:34 CEST 2010


This should be possible with rgeos, with the caveat that it may be fairly
slow, for the time being, if the number of points and or polygons is large.
The package is still in development so the documentation is still a work in
progress and there are not binaries available. If you get stuck I'd be happy
to help troubleshoot the installation.

You will want to use the gContains function, I have included a toy example
below to hopefully get you started:



library(rgeos)
gt <- GridTopology(c(0.05,0.05), c(.1,.1), c(10,10))
grd <- SpatialGrid(gt)
spi <- as(grd, "SpatialPixels")
spol <- as(spi, "SpatialPolygons")

set.seed(1)
x=runif(25)
y=runif(25)

pts = SpatialPoints(cbind(x,y))

ct = gContains( spol,pts,byid=c(TRUE,TRUE) )
colsub = apply(ct, 2,any)

plot(spol)
plot(spol[colsub,],add=T,col='green')
plot(pts,add=T)


If you have any questions or run into any bugs let me know.
-Colin
-- 
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/grid-and-spatial-selection-tp5329029p5331970.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list