Point-in-polygon lookup: given longitude / latitude vectors (or an sf POINT
object), return the iso3c of the country each point falls in – the bridge
for getting point data (events, stations, observations) onto the country
spine so it can be joined, aggregated and mapped like everything else.
Usage
locate_country(
lon = NULL,
lat = NULL,
points = NULL,
scale = "small",
add = "country",
tolerance_km = 25
)Arguments
- lon, lat
Numeric vectors of longitude / latitude (recycled together; ignored if
pointsis supplied).- points
Optional
sfPOINT object to use instead oflon/lat.- scale
Natural Earth resolution for the lookup geometry.
- add
Extra attributes to return alongside
iso3c(anyconvert_country()destination, e.g."country","continent").- tolerance_km
Snap an unmatched point to the nearest country when it lies within this many kilometres of one (default
25). Coarse (110m) coastlines place some genuinely-onshore coastal points just outside their country (New York sits ~0.5 km beyond the simplified US coast); this rescues them while leaving open-ocean pointsNA(the nearest land is hundreds of km away). Set0for a strict point-in-polygon lookup.
