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 imprecise 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.