Add support for signed 8 bit images#1595
Conversation
|
@sgillies I know that signed 8 bit images are a bit "dumb", but in our case we have a need to read NetCDF CF files, and NetCDF CF convention forbids unsigned integer types, so instead Rasterio behaviour of silently casting When you have an opportunity to look into this can you please let me know what your thoughts are on this:
|
sgillies
left a comment
There was a problem hiding this comment.
@Kirill888 this is great, and just how I would do it. Even better than I would have done it. Would you be willing to base this PR off the maint-1.0 branch so we can get it into 1.0.19?
Sorry for the delay!
Even though GDAL only has unsigned GDT_Byte raster data type, signed vs unsigned images can be differentiated via PIXELTYPE property. It is set to 'SIGNEDBYTE' for signed 8-bit images. This is how GDAL's native python binding compute numpy.dtype from dataset object.
|
Thanks @sgillies I have rebased to |
|
Cf OSGeo/gdal#6634 "RFC 87: Signed int8 data type for raster" that will likely be implemented in GDAL 3.7 |
Signed 8-bit images are somewhat "second-class" in GDAL, but it can read/write them nevertheless.
Even though GDAL only has unsigned
GDT_Byteraster data type, signed vs unsignedimages can be differentiated via
PIXELTYPEproperty. It is set toSIGNEDBYTEfor signed 8-bit file. This is how GDAL's native python binding compute
numpy.dtypefrom dataset object:https://github.com/OSGeo/gdal/blob/90dde4a3fc0d89373a62000ae14e424fc41f7306/gdal/swig/python/osgeo/gdal_array.py#L299-L300
Similarly, on output side, setting option
PIXELTYPE='SIGNEDBYTE'when creating file withGDT_Bytedtype will generate signed int8 image.