| dummies {rassta} | R Documentation |
Create Dummy Layers from Categorical Raster Layers
Description
Given a SpatRaster whose cell values represent categories (e.g., soil types, land use/cover classes), a dummy layer indicating the presence/absence of each category is created, and optionally written on disk. Each category in the raster layer must be represented by a unique integer cell value. Output values indicating the presence or absence of categories in the dummy layers may be set using preval and absval arguments, respectively.
Usage
dummies(
ca.rast,
vals = NULL,
preval = 100,
absval = 0,
to.disk = FALSE,
outdir = ".",
extension = ".tif",
...
)
Arguments
ca.rast |
SpatRaster, as in |
vals |
Integer. Vector or sequence of values representing the categories for which dummy layers will be created. If NULL, all categories will be processed. Default: NULL |
preval |
Integer. Value indicating presence of category. Default: 100 |
absval |
Integer. Value indicating absence of category. Default: 0 |
to.disk |
Boolean. Write output dummy layers to disk? Default: FALSE |
outdir |
Character. If to.disk = TRUE, string specifying the path for the output dummy raster layers. Default: "." |
extension |
Character. If to.disk = TRUE, String specifying the extension for the output raster layers (see Details). Default: ".tif" |
... |
If to.disk = TRUE, additional arguments as for
|
Details
This function mainly differs from segregate in
that presence and absence values can be set arbitrarily, thus allowing for
values other than those traditionally used in one-hot/dummy encoding (i.e.,
1 and 0).
Please note that the argument extension does not correspond to the
argument filetype in writeRaster. However,
writeRaster should recognize the appropriate extension
for the output raster layers from the extension argument. For
instance, by setting extension = ".tif",
writeRaster will recognize the extension as
GeoTiff, which is the GDAL driver name.
Value
Single-layer or multi-layer SpatRaster with dummy layer(s).
See Also
Other Miscellaneous Functions:
figure(),
plot3D()
Examples
require(terra)
p <- system.file("exdat", package = "rassta")
# Single-layer SpatRaster of geologic units
f <- list.files(path = p, pattern = "geology2.tif", full.names = TRUE)
geol <- terra::rast(f)
# Dummy layer from geologic unit 1
dums <- dummies(ca.rast = geol, vals = 1, preval = 100, absval = 0)