R/gpkg-util.R
gpkg_default_nodata.RdReturns a default NoData value for a given raster datatype, following GDAL
and terra conventions, and avoiding NaN values which produce a warning when
passed as data_null to GDAL. NOTE: at this time (GDAL 3.12) only Byte
(INT1U), Int16 (INT2S), UInt16 (INT2U) or Float32 (INT4S) datatypes are
supported in the GPKG raster driver.
gpkg_default_nodata(datatype)numeric. The default NoData value for the given datatype, or
NA_real_ if no default is available or the datatype is not recognized.
While NaN is technically a valid value for grids stored in a
geopackage, it is generally prefered to use a numeric value, as NaN is not
supported by SQLite 3 and is stored in the metadata column as SQL NULL.
These defaults are used by gpkg_write() when auto_nodata = TRUE.
For signed integer types, the minimum representable value (e.g., INT32_MIN) is returned, as it is unlikely to occur in valid data. For unsigned integer types, the maximum representable value is returned (e.g., UINT16_MAX), with the exception of INT1U (byte) which returns 255 (following terra convention). For float types, the negative extreme value is returned, as GeoPackage metadata cannot represent NaN.
| Datatype | Default NoData |
| INT1S | -128 |
| INT2S | -32768 |
| INT4S | -2147483648 |
| INT8S | -9223372036854775808 |
| INT1U | 255 |
| INT2U | 65534 |
| INT4U | 4294967295 |
| INT8U | 18446744073709549568 |
| FLT4S | -3.40282346638528860e+38 |
| FLT8S | -1.79769313486231571e+308 |
Note: The INT8U default (18446744073709549568) is UINT64_MAX - 1101 to
account for floating-point precision loss when converting to double,
following terra's convention. R does not have a native unsigned 64-bit
integer type.
gpkg_write() for using these defaults when writing rasters to
GeoPackage
gpkg_default_nodata("FLT4S")
#> [1] -3.402823e+38
gpkg_default_nodata("INT2S")
#> [1] -32768
gpkg_default_nodata("INT2U")
#> [1] 65535