[R] Identify points that lie within polygon

Ally a.rushworth at stats.gla.ac.uk
Mon Aug 6 17:05:52 CEST 2012


I have a complex 2D polygon with thousands of vertices, and I'd like to be
able to identify points from a large set contained within the polygon, and
was wondering if there might be an efficient way of doing this?  Any advice
would be useful!  Here is a small example of what I mean:

# make polygon
v1<-c(0,1,1,2,1,3,6,7)
v2<-c(1,3,3,5,6,7,8,9)
plot(v1, v2, type = "n" )
polygon(v1, v2, lwd = 2, col = "red")

# plot a set of candidate grid points
grid<-seq(0, 10, length.out = 30)
pts<-expand.grid(grid, grid)
points(pts, pch = 19, col = 1, cex = 1)

Many thanks!

Alastair




--
View this message in context: http://r.789695.n4.nabble.com/Identify-points-that-lie-within-polygon-tp4639289.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list