Extract Area-Weighted Mean from Numeric Raster Stack for Polygons
Source:R/extract_num_raster.R
extract_num_raster.RdCalculates the area-weighted mean value for each layer in a numeric SpatRaster
(or single layer) within each polygon feature of an sf object. This function
is designed for high-precision zonal statistics of continuous variables
(e.g., bioclimatic data).
Value
An sf object identical to sf_hex_grid, but with new columns
appended. The new column names match the original SpatRaster layer names.
The values represent the area-weighted mean for that variable within each polygon.
Details
The function uses exactextractr::exact_extract with fun = "weighted_mean"
and weights = "area" to ensure the most accurate sub-pixel summary. A critical
security check is implemented before binding columns (bind_cols) to prevent
data misalignment in case of row count discrepancies between the input features and
the extracted results.