R/parks_calc_attributes_helpers.R
raster_class_area.RdHelper function within parks_calc_attributes().
For each unique pixel value (each representing a specific raster class/category),
the total area per class is calculated.
raster_class_area(
polygons,
raster,
raster_min_patch_size = units::set_units(0, "m^2"),
relative = TRUE,
...
)sf (with projected coordinate reference system).
SpatRaster object from terra::rast(). Should have a (projected) coordinate reference system similar to polygons.
Minimum patch size to be included in results.
Provided either as a units object (see units::set_units()),
or a number in the units of the coordinate reference system. Defaults to 0 m^2.
logical. Whether or not to calculate relative amounts
(i.e. percentage area). Defaults to TRUE.
Other arguments passed to terra::extract().
polygons with added column(s) < class value >_area, and < class value >_area_pct if relative is set to TRUE.
Note that the value 0 will be summarised; convert pixels to NA if you wish to exclude them.