Two methods:
Usage
wet_ws_sample(r, ws, method = c("centroid", "area"))Arguments
- r
terra::SpatRaster, one or more layers.- ws
terra::SpatVectorof polygons with awatershed_feature_idattribute; or, for"centroid"only, adata.frame(watershed_feature_id, lon, lat)of centroids already computed (e.g. bywet_ws_fetch()), which avoids transferring geometry for a whole basin.- method
"centroid"or"area".
Value
For one layer, data.frame(watershed_feature_id, value, cover).
For several, data.frame(watershed_feature_id, <layer names>, cover).
Details
"centroid": the value of the cell containing each polygon's centroid (centroid taken in the polygons' own CRS, then reprojected). This is what fwapg does withST_Value(), and the method to use for a parity check.coveris 1 where the value is present and 0 where it isNA."area": the mean of every cell the polygon overlaps, weighted by the overlapping fraction, over cells that have a value.coveris the share of the polygon's overlap that falls on cells with a value, so a polygon half off the model domain reportscover = 0.5rather than a silently halved value downstream.
With several layers, a cell counts only where every layer has a value,
and all layers are averaged over those same cells. There is then one
cover per polygon, so upstream means of every layer share one
denominator and a linear combination of layers is exactly the same
combination of their means.
