Extracts summary statistics from a SpatRaster at point locations, optionally using buffered extraction with custom kernel windows.
Arguments
- x
SpatRaster. Input raster (single- or multi-layer).
- y
SpatVector. Points or polygons.
- d
numeric or numeric vector. Buffer radius/radii in map units.
- w
character. Window type for the buffer kernel when
d > 0
(currently passed through to terra; e.g., "circle", "rectangle").- fun
character or function. Summary function: "mean", "sum", "min", "max", "sd", or "median"; or a user function.
- na.rm
logical. Whether to remove NAs when computing summaries.
Value
A data.frame of extracted values. When d
has multiple values,
rows are stacked by scale with a scale_m
column indicating the radius.
Details
If
d > 0
, a buffer of radiusd
(map units) is created around each point and the summary is computed over raster cells intersecting the buffer.If
d == 0
, values are taken at the point locations (no buffering).If
y
is a polygon layer, the summary is computed over polygon areas.
Examples
r <- terra::rast(nrows = 10, ncols = 10, xmin = 0, xmax = 100, ymin = 0, ymax = 100)
terra::values(r) <- seq_len(terra::ncell(r))
pts <- terra::vect(
matrix(c(10, 10,
50, 50), ncol = 2, byrow = TRUE),
type = "points",
crs = terra::crs(r)
)
# Mean over a 20-unit circular neighborhood around each point
res <- fastextract(r, pts, d = 20, w = "circle", fun = "mean")
head(res)
#> lyr.1
#> 1 83.125
#> 2 50.500