Estimates mean values of raster cells for each polygon. Supports parallel processing, allowing each core to independently load and process raster layers from a NetCDF file. Used internally by pcp2swat_editor and tmp2swat_editor for SWAT input preparation.
Arguments
- grid
A `SpatRaster` object for single-core processing.
- geom
A set of polygons in `sf` format to perform the extraction.
- start_date
The start date for the time series.
- time_step
Time step between raster layers. Either 'day' or 'month'. Default is 'day'.
- cores
Number of cores for parallel processing. Default is 1 (single-core).
- grid_file
(Optional) Path to the NetCDF file for parallel processing.
See also
pcp2swat_editor, tmp2swat_editor,
pcp2swat, tmp2swat
Other Preprocessing tools:
pcp2swat(),
pcp2swat_editor(),
tmp2swat(),
tmp2swat_editor()
Examples
# \donttest{
# Example with package NetCDF data
pr_nc <- system.file("extdata", "pr.nc", package = "hydroSWAT")
data(subs1, package = "hydroSWAT")
grid <- terra::rast(pr_nc)
result <- areal_mean(grid, subs1, "2010-01-01", time_step = "day")
# }
if (FALSE) { # \dontrun{
# Example with external NetCDF and shapefile
grid <- terra::rast("path_to_raster_file.nc")
geom <- sf::st_read("path_to_shapefile.shp")
result <- areal_mean(grid, geom, "1981-01-01", time_step = "day",
cores = 2, grid_file = "path_to_netCDF.nc")
} # }