Skip to contents

Stratify based on polygon coverage attributes and features.

Usage

strat_poly(
  poly,
  attribute,
  features,
  raster,
  filename = NULL,
  overwrite = FALSE,
  plot = FALSE,
  details = FALSE
)

Arguments

poly

sf. Input polygon coverage. e.g. - forest resources inventory coverage.

attribute

Character. Name of attribute within poly that will be stratified.

features

Vector / list of vectors. Features within attribute to guide stratification.

raster

spatRaster. Raster template to enable polygon to raster conversion.

filename

Character. Path to write stratified raster to disc.

overwrite

Logical. Specify whether filename should be overwritten on disc.

plot

Logical. Plots output spatRaster.

details

Logical. If FALSE (default) output is spatRaster object of stratified polygon attributes. If TRUE return a list where $outRaster is the stratified attributes, $lookUp is the lookup table for the stratification, and poly is the defined polygon attribute with corresponding features / strata

Value

A spatRaster object.

See also

Other stratify functions: strat_breaks(), strat_kmeans(), strat_map(), strat_quantiles()

Author

Tristan R.H. Goodbody

Examples

#--- load input metrics raster ---#
raster <- system.file("extdata", "sraster.tif", package = "sgsR")
sraster <- terra::rast(raster)

#--- read polygon coverage ---#
poly <- system.file("extdata", "inventory_polygons.shp", package = "sgsR")
fri <- sf::st_read(poly)
#> Reading layer `inventory_polygons' from data source 
#>   `/home/runner/work/_temp/Library/sgsR/extdata/inventory_polygons.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 632 features and 3 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 431100 ymin: 5337700 xmax: 438560 ymax: 5343240
#> Projected CRS: UTM_Zone_17_Northern_Hemisphere

#--- stratify polygon coverage ---#
#--- specify polygon attribute to stratify ---#

attribute <- "NUTRIENTS"

#--- specify features within attribute & how they should be grouped ---#
#--- as a single vector ---#

features <- c("poor", "rich", "medium")

srasterpoly <- strat_poly(
  poly = fri,
  attribute = attribute,
  features = features,
  raster = sraster
)

#--- or as multiple lists ---#

g1 <- "poor"
g2 <- c("rich", "medium")

features <- list(g1, g2)

srasterpoly <- strat_poly(
  poly = fri,
  attribute = attribute,
  features = features,
  raster = sraster,
  details = TRUE
)