0

I am currently using gdallocationinfo and I am calling it thousands of times on a project. It gives warnings which I can disregard. However the warnings are being printed to the screen and it is slowing the project down in doing so. Is there some way to run this in quiet mode? I do not see a "-q" in the documentation at https://gdal.org/programs/gdallocationinfo.html.

Here is what I want to silence in the command prompt :

Warning 1: 1715.tif: TIFFFetchNormalTag:incorrect count for field "PageNumber", expected 2, got 1

Warning 1: 1715.tif: TIFFFetchNormalTag:Incompatible type for "GDALNoDataValue"; tag ignored

David
  • 232
  • 5
  • 21

2 Answers2

1

I would consider to fix the TIFF images instead if they were in my control by rewriting them with gdal_translate.

Silencing the warnings would require edits into source code but the errors that you see do not come directly from gdallocationinfo https://github.com/OSGeo/gdal/blob/master/apps/gdallocationinfo.cpp but from the GeoTIFF driver https://github.com/OSGeo/gdal/tree/master/frmts/gtiff and finally from libtiff library https://github.com/OSGeo/gdal/blob/master/frmts/gtiff/libtiff/tif_dirread.c

Probably the errors from drivers could be silenced around here https://github.com/OSGeo/gdal/blob/380edbda33302f32dadb46ce46489e4d1cd140db/apps/gdallocationinfo.cpp#L185 where the datasource is opened with "verbose error" option

= GDALOpenEx( pszSrcFilename, GDAL_OF_RASTER | GDAL_OF_VERBOSE_ERROR,

user30184
  • 65,331
  • 4
  • 65
  • 118
  • This is exactly the answer I was looking for. I can't change the source of the TIFF file. But could I simply "convert" the TIFF to a new TIFF using gdal_translate to fix this? It would literally just be a copy, but it would still save time for me. – David Nov 18 '21 at 19:14
  • 1
    I am pretty sure that a new tiff written with gdal_translate would not show those messages about invalid tiff tags. – user30184 Nov 18 '21 at 20:29
1

If you can call gdallocationinfo from Python, you may get over this:

from subprocess import run
retval = subprocess.run(['gdallocationinfo', '-wgs84', fich, x, y],
                        capture_output=True, text=True
                       )

Output is stored in retval.stdout

However, if using Python anyway, you may want to just bypass gdallocationinfo and extract your data in Python directly.

Jose
  • 3,332
  • 20
  • 21
  • 2> nul can be appended to the command on Windows to suppress stderr, to a similar effect – mikewatt Nov 23 '21 at 19:39
  • @Jose "However, if using Python anyway, you may want to just bypass gdallocationinfo and extract your data in Python directly. - How is this most easily done? I don't code in python (just c++) but I am sure I could figure it out with some direction. This would be much faster than calling gdallocationinfo from the command line, and speed is really hurting me right now. – David Nov 24 '21 at 19:27
  • You may want to have a look at this post. If you need more help, open a new question. – Jose Nov 25 '21 at 11:27