
Recover administrative info for point data via a spatial join
Source:R/spatial.R
get_admin_info_from_coords.RdBuilds point geometries from a data frame's longitude/latitude columns,
spatially joins them to a district (adm2) shape table, optionally filtering
the join to shapes whose validity window (year_start..year_end) contains
the point's year, and fills any missing admin names/GUIDs from the matched
shape. Points that match more than one shape (e.g. on a boundary) are dropped
rather than guessed.
Usage
get_admin_info_from_coords(
data,
shp_adm2,
year_col = NULL,
lon_var = "longitude",
lat_var = "latitude",
crs = 4326
)Arguments
- data
A data frame with
lon_varandlat_varcolumns, and optionallyadm0and ayear_col.- shp_adm2
An
sfobject of district boundaries carrying the canonical admin name columns (adm0/adm1/adm2) and GUID columns, and, for temporal filtering,year_start/year_end.- year_col
Optional name of the year column in
data. When supplied and present, the join is filtered to temporally valid shapes. DefaultNULL.- lon_var
Longitude column name. Default
"longitude".- lat_var
Latitude column name. Default
"latitude".- crs
CRS of the input coordinates as an EPSG code. Default
4326.