Performs a spatial join to obtain geographic fields for specified lon/lat columns.
Usage
join_spatial(
x,
y,
id_col,
lon_col,
lat_col,
crs_lonlat = 4326,
crs_equal_area = 5070,
largest = FALSE
)
Arguments
- x
A data.table of survey data
- y
an
sf
object with the geometry of interest- id_col
character. The column in
x
that is a unique identifier- lon_col
character. The column in
x
that has longitude- lat_col
character. The column in
x
that has latitude- crs_lonlat
numeric. The EPSG code for lonlat data (defaults to WGS84)
- crs_equal_area
numeric. The EPSG code for an equal area projection. Many spatial operations assume projected data (not lon/lat). Defaults to US Albers Equal Area
- largest
logical. If
TRUE
, returnx
features with fields ofy
that have the largest overlap with each of the features ofx
; seest_join
. This is useful if join is returning more than one value of y for each x.
Examples
if (FALSE) {
x = data.table(id = 1:3, lon = c(-82.33, -79.17, -76.17), lat = c(35.50, 36.27, 36.49))
nc = st_read(system.file("shape/nc.shp", package = "sf"))[, c("FIPS", "NAME", "geometry")]
z = join_spatial(x, nc, id_col = "id", lon_col = "lon", lat_col = "lat")
z
}