Apply class names and a color table to a categorical SpatRaster, optionally
remapping (collapsing) classes into broader groups.
Arguments
- x
A terra::SpatRaster or a named list of
SpatRasters (e.g. fromdft_stac_fetch()).- class_table
A tibble with columns
code,class_name,color(hex). WhenNULL, loaded viadft_class_table()usingsource.- source
Character. Used to load a shipped class table when
class_tableisNULL. One of"io-lulc"or"esa-worldcover".- remap
A named list for collapsing classes. Names are the new class names, values are character vectors of original
class_names to merge. For example,list(Vegetation = c("Trees", "Rangeland")). WhenNULL, no remapping is applied.
Value
Same structure as x — a SpatRaster or named list — with
terra::levels() and terra::coltab() set.
Examples
r <- terra::rast(system.file("extdata", "example_2020.tif", package = "drift"))
classified <- dft_rast_classify(r, source = "io-lulc")
terra::is.factor(classified)
#> [1] TRUE
