Skip to contents

Extracts cell values from x at each location in points. Points are reprojected to the raster CRS if needed (a warning is issued when this happens). The returned data.frame has the same number of rows as points with one additional column per raster layer.

Usage

extract_points(x, points, bind = TRUE, ...)

Arguments

x

A SpatRaster with one or more layers.

points

An sf or SpatVector of point locations.

bind

Logical; if TRUE (default), the extracted values are column-bound to the attributes of points. If FALSE, only the extracted values are returned.

...

Additional arguments passed to terra::extract().

Value

A data.frame.

Examples

if (FALSE) { # \dontrun{
library(terra)
library(sf)
r   <- rast(nrows = 10, ncols = 10, crs = "EPSG:4326")
r[] <- 1:ncell(r)
pts <- st_as_sf(
  data.frame(id = 1:3, x = c(-1, 0, 1), y = c(-1, 0, 1)),
  coords = c("x", "y"), crs = 4326
)
extract_points(r, pts)
} # }