Skip to contents

Joins attributes from a polygon layer to point locations by spatial overlay. Each point receives the attributes of the polygon it falls within. Points outside all polygons receive NA for the joined columns. Commonly used to attach natural subregion, LUF zone, ownership, or watershed identifiers.

Usage

extract_vector(points, polygons, cols = NULL, ...)

Arguments

points

An sf object (point geometry).

polygons

An sf polygon layer with attributes to join.

cols

Character vector of column names from polygons to retain. NULL (default) retains all non-geometry columns.

...

Additional arguments passed to sf::st_join().

Value

An sf object with the same geometry as points and additional columns from polygons.

Examples

if (FALSE) { # \dontrun{
library(sf)
pts  <- st_as_sf(data.frame(id = 1, x = -114, y = 53),
                 coords = c("x", "y"), crs = 4326)
poly <- st_read("natural_subregions.gpkg")
pts_joined <- extract_vector(pts, poly, cols = "NRNAME")
} # }