raster_class_area: Calculate the total class area of a (classified) raster for...

View source: R/parks_calc_attributes_helpers.R

raster_class_areaR Documentation

Calculate the total class area of a (classified) raster for each park polygon.

Description

Helper function within parks_calc_attributes(). For each unique pixel value (each representing a specific raster class/category), the total area per class is calculated.

Usage

raster_class_area(
  polygons,
  raster,
  raster_min_patch_size = units::set_units(0, "m^2"),
  relative = TRUE,
  ...
)

Arguments

polygons

sf (with projected coordinate reference system).

raster

SpatRaster object from terra::rast(). Should have a (projected) coordinate reference system similar to polygons.

raster_min_patch_size

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.

relative

logical. Whether or not to calculate relative amounts (i.e. percentage area). Defaults to TRUE.

...

Other arguments passed to terra::extract().

Value

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.


ecological-cities/home2park documentation built on Dec. 6, 2023, 1:05 a.m.