gpkg_default_nodata: Get Default NoData Value for GeoPackage Raster Datatypes

View source: R/gpkg-util.R

gpkg_default_nodataR Documentation

Get Default NoData Value for GeoPackage Raster Datatypes

Description

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

Usage

gpkg_default_nodata(datatype)

Arguments

datatype

character. A raster datatype code in terra format. Supported types are:

  • Signed integers: "INT1S", "INT2S", "INT4S", "INT8S"

  • Unsigned integers: "INT1U", "INT2U", "INT4U", "INT8U"

  • Floats: "FLT4S" (single precision), "FLT8S" (double precision)

Details

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.

Value

numeric. The default NoData value for the given datatype, or NA_real_ if no default is available or the datatype is not recognized.

See Also

gpkg_write() for using these defaults when writing rasters to GeoPackage

Examples

gpkg_default_nodata("FLT4S")
gpkg_default_nodata("INT2S")
gpkg_default_nodata("INT2U") 


gpkg documentation built on April 3, 2026, 9:08 a.m.