4

When calling gdalinfo with certain options, it creates an auxiliary file which has a side-effect on other options.

Let’s say I want to compute the min/max value on elevation data from a GeoTIFF file. I am using the -mm option:

gdalinfo /path/to/file.tif -mm

It returns the usual gdalinfo output with image size, projection, etc. plus the following due to the -mm option:

  Computed Min/Max=592.000,2737.412

So far so good.

I can also compute approximate stats:

gdalinfo /path/to/file.tif -approx_stats

Which adds this output:

  Minimum=611.662, Maximum=2737.412, Mean=1461.410, StdDev=414.722
  Metadata:
    STATISTICS_MAXIMUM=2737.412109375
    STATISTICS_MEAN=1461.4103933815
    STATISTICS_MINIMUM=611.66223144531
    STATISTICS_STDDEV=414.72166382554

Values are slightly different, probably due to the approximation, but it’s not an issue for me.

However, this call also writes an auxiliary file next to the original file, e.g. /path/to/file.tif.aux.xml

This has several downsides. First, it creates a file on a folder where I should not be writing into. Secondly, it now pollutes basically every call to gdalinfo on that same file.

For instance if I call gdalinfo with -mm exactly like the first call, the statistics are always output, mixing the approximate and "real" min/max:

  Min=611.662 Max=2737.412   Computed Min/Max=592.000,2737.412
  Minimum=611.662, Maximum=2737.412, Mean=1461.410, StdDev=414.722
  Metadata:
    STATISTICS_MAXIMUM=2737.412109375
    STATISTICS_MEAN=1461.4103933815
    STATISTICS_MINIMUM=611.66223144531
    STATISTICS_STDDEV=414.72166382554

I am currently deleting the auxiliary file after every call to gdalinfo that writes one, but I would prefer a solution that does not write that file to begin with.

PS. adding the -nomd option (no metadata) suppresses metadata from the console output, but the auxiliary file is still written to disk.

2
  • did you look at the code?
    – Ian Turton
    Commented Dec 8, 2020 at 20:34
  • About writing to a folder where you should not to write, gdalinfo -stats writes statistics into the tags of the GeoTIFF file if they are missing. Is that OK for you or should you make the files as read-only?
    – user30184
    Commented Dec 9, 2020 at 6:58

1 Answer 1

3

Run your command with a configuration option GDAL_PAM_ENABLED set to NO.

gdalinfo /path/to/file.tif -approx_stats --config GDAL_PAM_ENABLED NO 
6
  • It does not create the auxiliary file, but I get 3 errors at the end: ERROR 6: /path/to/file.tif, band 1: SetOffset() not supported on this raster band and the same error with SetScale() and SetUnitType(). I should mention that statistics are computed regardless of those errors so I guess they are merely informational.
    – vdavid
    Commented Dec 9, 2020 at 9:40
  • Maybe that's why the aux.xml file is normally created. Perhaps there is no place to store that metadata into TIFF/GeoTIFF tags and therefore they are stored as "persistent auxiliary metadata" into the sidecar file.
    – user30184
    Commented Dec 9, 2020 at 9:45
  • OK so with other file formats, it may modify the original file? I so, it is an even worse situation than the auxiliary file.
    – vdavid
    Commented Dec 9, 2020 at 10:07
  • Statistics and histograms are useful and they are slow to compute so storing them as metadata makes sense. If original image has metadata it is not modified. If you compute the statistics (not estimate) the information is correct so why not to write it into the metadata?
    – user30184
    Commented Dec 9, 2020 at 10:17
  • 1
    They way I see it, gdalinfo is supposed to gather information from data, not modify them, otherwise I may meet race conditions when several programs call gdalinfo simultaneously on the same file. If it does not modify files then the GDAL_PAM_ENABLED option is exactly what I need.
    – vdavid
    Commented Dec 9, 2020 at 10:38

Your Answer

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

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