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.
Hello, With your example run and click 10 black points inside the area. ploc <- locator(n=10) points(ploc$x, ploc$y, pch = 19, col = "green", cex = 1) Hope this helps, Rui Barradas Em 06-08-2012 16:05, Ally escreveu:> 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. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
This is off-topic (not about R), and a quick Web search of "test within polygon" yields many results, and adding "R" to the search when using Google provides hints about applying the algorithms in R. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Ally <a.rushworth at stats.gla.ac.uk> wrote:>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. > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
Reasonably Related Threads
- help with using grid.polygon()
- Passing lists between functions
- Row-wise kronecker product with Matrix package
- Determine if a set of x and y-latitude points are inside of a polygon using R
- How do I ensure that the polygon in spatstat::owin(poly=<polygon>) does not have “negative area”