The values in a SpatRaster layer are by default numeric, but they can also be set to be logical (Boolean), integer, or categorical (factor).
For a SpatRaster
, as.logical
and isTRUE
is equivalent to as.bool
. isFALSE
is equivalent to !as.bool
, and as.integer
is the same as as.int
.
as.bool
and as.int
force the values into the correct range (e.g. whole integers) but in-memory cell values are still stored as numeric. They will behave like the assigned types, though, and will be written to files with that data type (if the file type supports it).
See levels
and cats
to create categorical layers by setting labels.