Skip to contents

Stratify metrics raster using user defined breaks

Usage

strat_breaks(
  mraster,
  breaks,
  map = FALSE,
  plot = FALSE,
  details = FALSE,
  filename = NULL,
  overwrite = FALSE
)

Arguments

mraster

Spatraster. Raster to stratify. Layers in mraster must match the number of breaks vectors provided.

breaks

Numeric. Vector of breakpoints for each layer of mraster. If mraster has multiple layers, breaks 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. raster is a stratified spatRaster based on quantiles. If stack = TRUE will be the number of layers of mraster plus the final output

  2. breaks is a list output of breaks

  3. plot is a ggplot histogram object showing distribution(s) and break point(s).

See also

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

Author

Tristan R.H. Goodbody

Examples

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

#--- create vector breaks ---#
br.zq90 <- c(3, 5, 11, 18)
br.pz2 <- c(20, 40, 60, 80)

strat_breaks(
  mraster = mr$zq90,
  breaks = br.zq90
)
#> 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
#> varname     : mraster 
#> name        : strata 
#> min value   :      1 
#> max value   :      5 


strat_breaks(
  mraster = mr[[1:2]],
  breaks = list(br.zq90, br.pz2),
  details = TRUE
)
#> $breaks
#> # A tibble: 22 × 3
#>    strata_zq90 strata_pzabove2 strata
#>          <dbl>           <dbl>  <int>
#>  1           1               1      1
#>  2           1               2      2
#>  3           2               1      3
#>  4           2               2      4
#>  5           2               3      5
#>  6           2               4      6
#>  7           2               5      7
#>  8           3               1      8
#>  9           3               2      9
#> 10           3               3     10
#> # ℹ 12 more rows
#> 
#> $raster
#> class       : SpatRaster 
#> dimensions  : 277, 373, 2  (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
#> varnames    : mraster 
#>               mraster 
#> names       : strata, strata 
#> min values  :      1,      1 
#> max values  :      5,      5 
#> 
#> $plot
#> NULL
#>