5

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 ?

asked Jan 23, 2018 at 11:04

2 Answers 2

4

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

answered Nov 26, 2019 at 20:39
3

This is an interesting problem. To my knowledge, GDAL does not support interpretation of signed 8-bit data. Even raster formats that can handle signed bytes SDAT, for instance are coerced to handle GDT_Byte I think...

The obvious solution to your underlying problem is to use a nodata value like 255 if you really care about the file storage size. Otherwise use a signed 16-bit image and some compression if the format supports it. You may find it plenty suitable.

answered Jan 23, 2018 at 14:57
1
  • Thanks a lot for your answer. I actually used a 16bit image, but due to the large size I guess we'll switch to Bytes with 255 for NoData, which is the simplest way. Anyway, it would be an interesting feature for future of GDAL to have signed Bytes ! Commented Jan 25, 2018 at 15:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.