I have GPS coordinates in degrees within a data frame that I converted to the class SpatialPointsDataFrame. Also, I have a polygon object of the US border of the class SpatialPolygons. How can I check if the coordinates in the data frame are within the polygon?
This is my US_Border polygon and GPS Coordinates:
States <- raster::getData("GADM", country = "United States", level = 1)
US_Border <- rgeos::gUnaryUnion(States, id = States$ISO)
df <- data.frame(long = c(-64.70165790479105, -127.0546743044134, -123.8361408468202, -78.01064761813421, -64.70165790479105),
lat = c(46.54000819626808, 50.41093540503351, 30.37665910843564, 24.54447072686601, 46.54000819626808))
coordinates(df) <- ~ long + lat
And the result shows that none of the 5 points are in the US domain:
although coordinates are longitude/latitude, st_contains assumes that they are planar
Sparse geometry binary predicate list of length 5, where the predicate was `contains'
1: (empty)
2: (empty)
3: (empty)
4: (empty)
5: (empty)