In an earlier post I reported about my attempts to read TIFF with data stored in tiles using python and libtiff. First I tried to use libtiff's function TIFFReadEncodedTile but finally I tried function TIFFReadTile. I have been able to make progress now. The question I have today: how can I retrieve the value of private / custom tag GDAL_NODATA. Both GDAL and ArcGIS make use of this tag. I've seen examples of how to do this in C++ and C#. I still wonder how to do this in Python though. I guess it would be possible by means of the class TIFFExtender and the function add_tags - both defined in module libtiff_ctypes. Could anybody provide an example?

  • ArcGIS doesn't read this tag directly. As of v. 10 ArcGIS uses GDAL to read rasters. – user2856 Mar 8 '16 at 20:09

I've now figured out how to go about it. Before "libtiff.libtiff_ctypes.add_tags(extra_tags)" and before opening the TIFF file, I added this code:

from libtiff.libtiff_ctypes import TIFFFieldInfo, TIFFDataType, FIELD_CUSTOM
extra_tags = [
    TIFFFieldInfo(42113, -1, -1, TIFFDataType.TIFF_ASCII, FIELD_CUSTOM, True, False, "GDAL_NODATA"),
    TIFFFieldInfo(33550, 3, 3, TIFFDataType.TIFF_DOUBLE, FIELD_CUSTOM, True, False, "ModelPixelScaleTag"),
    TIFFFieldInfo(33922, 6, 6, TIFFDataType.TIFF_DOUBLE, FIELD_CUSTOM, True, False, "ModelTiepointTag"),
    TIFFFieldInfo(42112, -1, -1, TIFFDataType.TIFF_ASCII, FIELD_CUSTOM, True, False, "GDAL_METADATA")

I have added 3 other tags which are added when ArcGIS exports TIFF. You can then call: GetField("GDAL_NODATA")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.