Skip to contents

Map stratified rasters to a combined stratification.

Usage

strat_map(
  sraster,
  stack = FALSE,
  filename = NULL,
  overwrite = FALSE,
  plot = FALSE,
  details = FALSE
)

Arguments

sraster

spatRaster or list. Stratification raster stack or list of rasters. If sraster is of class list, then it is internally converted into a raster stack.

stack

Logical. Default = FALSE. If TRUE, inputs and output will be stacked: strata_1, strata_2, ..., strata.

filename

Character. Path to write stratified raster to disc.

overwrite

Logical. Specify whether filename should be overwritten on disc.

plot

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

details

Logical. If FALSE (default) output is a mapped stratified spatRaster object. If TRUE return a list where $outRaster is the mapped stratified raster, and $lookUp is the lookup table for the stratification.

Value

A spatRaster object.

Mapping

The mapping algorithm will take the stratification from sraster and combine it with overlying strata values across all layers. This will result in a strata attribute where the values from all inputs are combined.

i.e.

If strata_1 = 1 and strata_2 = 1 then strata = 11.

If strata_1 = 2 and strata_2 = 14 then strata = 214.

If strata_1 = "A" and strata_2 = 14 then strata = "A14".

See also

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

Author

Tristan R.H. Goodbody, Tommaso Trotto, Robert Hijmans

Examples

#--- load input metrics rasters ---#
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")

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

#--- map srasters with raster stack ---#
stack <- c(srasterfri, sraster)
strat_map(
  sraster = stack
)
#> 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     : sraster 
#> name        : strata 
#> min value   :     11 
#> max value   :     34 

#--- map sraster with list of rasters ---#
rast_list <- list(srasterfri, sraster)
strat_map(
  sraster = rast_list,
  stack = TRUE,
  details = TRUE
)
#> Stacking srasters and their combination (strata).
#> $raster
#> 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 
#> sources     : memory  
#>               sraster.tif  
#>               memory  
#> varnames    : sraster 
#>               sraster 
#>               sraster 
#> names       : strata_1, strata_2, strata 
#> min values  :        1,        1,     11 
#> max values  :        3,        4,     34 
#> 
#> $lookUp
#>    strata_1 strata_2 strata
#> 1         1        1     11
#> 2         1        2     12
#> 3         1        3     13
#> 4         1        4     14
#> 5         2        1     21
#> 6         2        2     22
#> 7         2        3     23
#> 8         2        4     24
#> 9         3        1     31
#> 10        3        2     32
#> 11        3        3     33
#> 12        3        4     34
#>