2

I am trying to use GDAL Python API to deal with some big raster, and when I read these rasters into Python, I get warnings like that:

Warning 1: TIFFFetchNormalTag:ASCII value for tag "GeoASCIIParams" contains null byte in value; value incorrectly truncated during reading due to implementation limitations
Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.
Warning 1: TIFFFetchNormalTag:ASCII value for tag "GeoASCIIParams" contains null byte in value; value incorrectly truncated during reading due to implementation limitations
Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.

Do anybody encounter problems like this? Why did this thing happen?

The raster I use is about 2.2G for one raster, and the raster' format is TIFF.the warnings don't affect the later use of the data, it is still an annoying issue, I want to know how to fix this.

TomazicM
27.3k25 gold badges33 silver badges43 bronze badges
asked Aug 19, 2019 at 3:57

2 Answers 2

7

You can suppress the warnings (as long as you're sure there's no real issue with your data) with gdal.PushErrorHandler('CPLQuietErrorHandler'). If you do this any errors will also not get printed, so make sure you tell GDAL to raise a Python exception when an error occurs with gdal.UseExceptions().

E.g.

# Stop GDAL printing both warnings and errors to STDERR
gdal.PushErrorHandler('CPLQuietErrorHandler')
# Make GDAL raise python exceptions for errors (warnings won't raise an exception)
gdal.UseExceptions()
answered Aug 19, 2019 at 5:22
1
  • Thanks for your contribution, it worked very well Commented Aug 20, 2019 at 1:27
5

The first warning means that the value of GeoASCIIParams tag is not read as it was written because the original image is having NULL character in the value of the tag. NULL can be used as a delimiter between strings http://freeimage.sourceforge.net/fnet/html/A633E9A9.htm but obviously GDAL takes just the first string.

The second error means that the writer that created the TIFF file has written the metadata wrong. Perhaps the metadata tells that image is of RGB type without extra samples (bands) but actually the image has four bands and GDAL considers it as RGBA. By doing that GDAL at least doesn not drop a band but it may make a wrong guess about the role of the extra band which is not necessarily alpha but could contain data as well (for example RGB+Near Infrared).

answered Aug 19, 2019 at 6:13
6
  • I am not familiar with C++, so what effect will it be if GDAL just takes the first string? It seems that this warning does not affect anything for now.@user30184 Commented Aug 19, 2019 at 8:06
  • I believe it does not make any harm at all but it would be nice to see the value of the tag GeoASCIIParams. Can you check the tag or share the original image? Commented Aug 19, 2019 at 8:24
  • I could share the original image,it is the sentinel-2 image and I converted it into TIFF, how could I share the image to you?@user30184 Commented Aug 19, 2019 at 8:45
  • Could you first try if the listgeo program could show the contents of GeoASCIIParams? Commented Aug 19, 2019 at 10:14
  • Perhaps a better utility to use is tiffdump. Usage: tiffdump -m 1000 image.tif >dumped_tags.txt. Commented Aug 19, 2019 at 15:18

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.