Data type of a SpatRaster or SpatVector
datatype.Rd
Get the data types of the fields (attributes, variables) of a SpatVector or of the file(s) associated with a SpatRaster. A (layer of a) SpatRaster has no datatype if it has no values, or if the values are in memory.
Usage
# S4 method for class 'SpatRaster'
datatype(x, bylyr=TRUE)
# S4 method for class 'SpatVector'
datatype(x)
Details
Setting the data type is useful if you want to write values to disk with writeRaster
. In other cases you can use functions such as round
and floor
, or as.bool
raster datatypes are described by 5 characters. The first three indicate whether the values are integer or decimal values. The fourth character indicates the number of bytes used to save the values on disk, and the last character indicates whether the numbers are signed (that is, can be negative and positive values) or not (only zero and positive values allowed)
The following raster datatypes are available:
Datatype definition | minimum possible value | maximum possible value |
INT1U | 0 | 255 |
INT2U | 0 | 65,534 |
INT4U | 0 | 4,294,967,296 |
INT8U | 0 | 18,446,744,073,709,551,616 |
INT2S | -32,767 | 32,767 |
INT4S | -2,147,483,647 | 2,147,483,647 |
INT8S | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,808 |
FLT4S | -3.4e+38 | 3.4e+38 |
FLT8S | -1.7e+308 | 1.7e+308 |
For all integer types, except the single byte types, the lowest (signed) or highest (unsigned) value is used to store NA
.
Note that very large integer numbers may be inpreceise as they are internally represented as decimal numbers.
INT4U
is available but they are best avoided as R does not support 32-bit unsigned integers.
See also
Raster data types
to check / set the type of SpatRaster values.
Examples
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
datatype(v)
#> [1] "double" "string" "double" "string" "double" "double"
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
datatype(r)
#> [1] "INT2S"
# no data type
datatype(rast())
#> [1] ""