Skip to contents

Stratify metrics raster using kmeans algorithm

Usage

strat_kmeans(
  mraster,
  nStrata,
  iter = 500,
  algorithm = "Lloyd",
  center = TRUE,
  scale = TRUE,
  plot = FALSE,
  details = FALSE,
  filename = NULL,
  overwrite = FALSE,
  ...
)

Arguments

mraster

spatRaster. ALS metrics raster.

nStrata

Numeric. Number of desired strata.

iter

Numeric. The maximum number of iterations allowed.

algorithm

Character. "Lloyd" (default) or "MacQueen" algorithms.

center

Logical. Value indicating whether the variables should be shifted to be zero centered.

scale

Logical. Value indicating whether the variables should be scaled to have unit variance.

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.

...

Additional arguments to be passed to kmeans function.

Value

output stratification spatRaster, or a list when details = TRUE.

See also

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

Author

Tristan R.H. Goodbody

Examples

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

#--- perform stratification using k-means ---#
kmeans <- strat_kmeans(
  mraster = mr,
  nStrata = 5
)
#> K-means being performed on 3 layers with 5 centers.

kmeans <- strat_kmeans(
  mraster = mr,
  nStrata = 5,
  iter = 1000,
  algorithm = "MacQueen",
  details = TRUE
)
#> K-means being performed on 3 layers with 5 centers.