0

I have my polygons stored in a SpatialPolygonsDataFrame and my coordinates in a data frame.

The output I want is to just have an additional column on my data frame that tags the OBJECTID (id of the polygon from the shapefile) that the coordinates fall into.

My problem is kind of the same with this

But its output is a little bit different. Also, it's kinda slow. I tried to tag just 4 coordinates and it took more than 5 minutes. I'm gonna be tagging 16k coordinates so would it be possible to do it faster?

wibeasley
  • 5,000
  • 3
  • 34
  • 62
Brent Carbonera
  • 448
  • 2
  • 5
  • 9

1 Answers1

0

The current methods I know about wouldn't do that exactly (i.e., produce one polygon id per coordinate) because they're generalized in case one point is contained in multiple (overlapping polygons).

See sp::over(), which used to be called overlay().

Example:

over(sr, geometry(meuse), returnList = TRUE)
over(sr, meuse, returnList = TRUE)

Possible duplicates (it's hard to tell without seeing your example data):

wibeasley
  • 5,000
  • 3
  • 34
  • 62
  • The over function is on-point with my use! The cbind use from your second article also came in handy. I've been forcing myself to use gContains but now I see it has a different use. Thanks for the help. – Brent Carbonera Mar 15 '18 at 03:33
  • Glad to hear it. Consider if these either of these actions adds info to the question: https://stackoverflow.com/help/someone-answers – wibeasley Mar 15 '18 at 04:11