I'm trying to determine if a point falls within a JSON sf. There were several postings that indicated the "over" function in the "sp" package would work, but I'm getting an error.
northamerica <- geojsonsf::geojson_sf("data/custom.geo.json") #source: https://geojson-maps.ash.ms/ - Regions - north america
northamerica <- sf::st_transform(northamerica,crs=4326)
pts <- data.frame(click=1,lat=37.43997, lng=277.9102)
pts <- sf::st_as_sf(x = pts,coords = c("lng", "lat"),
crs = 4326)
sp::over(pts,northamerica)
I get the following error when I run the above code:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘over’ for signature ‘"sf", "sf"’
Any ideas why I'm getting this error or suggestions on an alternative method?
I realized that with sf objects that I needed to us "sf_within" instead of "over" from the sp package. Still learning spatial data in R.