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 ofbreaks
vectors provided.- breaks
Numeric. Vector of breakpoints for each layer of
mraster
. Ifmraster
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 eachmraster
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. IfTRUE
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:
raster
is a stratifiedspatRaster
based on quantiles. Ifstack = TRUE
will be the number of layers ofmraster
plus the final outputbreaks
is a list output ofbreaks
plot
is aggplot
histogram object showing distribution(s) and break point(s).
See also
Other stratify functions:
strat_kmeans()
,
strat_map()
,
strat_poly()
,
strat_quantiles()
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
#>