[GIS] Using signed Bytes with GDAL

gdalgdal-rasterizepythonraster

In the list of raster pixel data types that are available with GDAL, the "smallest" types are Bytes, UInt16 and Int16. I would like to store integers from 0 to 100 in the smallest image type, but with the constraint of using -1 and -2 for NoData value and other specific value. GDAL Bytes are unsigned, so the smallest type would be Int16.
http://www.gdal.org/gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4

I use this type to create rasters, with the Rasterize function in Python bindings.

Do you know if there is a trick to use signed Bytes ?

Best Answer

If you want to use signed 8bit integers for GeoTIFFs use datatype Byte together with creation options PIXELTYPE=SIGNEDBYTE

https://gdal.org/drivers/raster/gtiff.html

gdal_translate -ot Byte -a_nodata -1 -co PIXELTYPE=SIGNEDBYTE input.tif output.tif