Skip to contents

Stratify metric raster using metric quantiles.

Usage

strat_quantiles(
  mraster,
  nStrata,
  map = FALSE,
  plot = FALSE,
  details = FALSE,
  filename = NULL,
  overwrite = FALSE
)

Arguments

mraster

spatRaster. ALS metrics raster.

nStrata

Numeric. A positive integer representing the number of desired classes or a numeric vector of probabilities with values between 0-1. If mraster has multiple layers, nStrata must be a list with an equal number of objects.

map

Logical. Map individual stratified layers to a combined stratification. Will output a multi-layer SpatRaster with individual stratifications for each mraster layer and an additional mapped stratification named "strata".

plot

Logical. Plots output strata raster and visualized strata with boundary dividers.

details

Logical. If FALSE (default) output is only stratification raster. If TRUE return a list where $details is additional stratification information and $raster is the output stratification spatRaster.

filename

Character. Path to write stratified raster to disc.

overwrite

Logical. Specify whether filename should be overwritten on disc.

Value

Returns an output stratification spatRaster or a list when details = TRUE.

When a list is returned:

  1. details lookUp table for stratification(s).

  2. raster is a stratified spatRaster based on quantiles

  3. plot is a ggplot histogram / scatter plot object (depends on whether metric2 was supplied). Histogram shows distribution and break points.

See also

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

Author

Tristan R.H. Goodbody

Examples

#--- Load raster and existing plots---#
r <- system.file("extdata", "mraster.tif", package = "sgsR")
mr <- terra::rast(r)

strat_quantiles(
  mraster = mr$zq90,
  nStrata = 4
)
#> class       : SpatRaster 
#> dimensions  : 277, 373, 1  (nrow, ncol, nlyr)
#> resolution  : 20, 20  (x, y)
#> extent      : 431100, 438560, 5337700, 5343240  (xmin, xmax, ymin, ymax)
#> coord. ref. : UTM Zone 17, Northern Hemisphere 
#> source(s)   : memory
#> name        : strata 
#> min value   :      1 
#> max value   :      4 

strat_quantiles(
  mraster = mr[[1:2]],
  nStrata = list(c(0.2,0.4,0.8), 3),
  map = TRUE
)
#> Mapping stratifications.
#> class       : SpatRaster 
#> dimensions  : 277, 373, 3  (nrow, ncol, nlyr)
#> resolution  : 20, 20  (x, y)
#> extent      : 431100, 438560, 5337700, 5343240  (xmin, xmax, ymin, ymax)
#> coord. ref. : UTM Zone 17, Northern Hemisphere 
#> source(s)   : memory
#> names       : strata_zq90, strata_pzabove2, strata 
#> min values  :           1,               1,      1 
#> max values  :           4,               3,     12