1

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 Dec 8 '20 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 Dec 9 '20 at 6:58
1

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 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 Dec 9 '20 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 Dec 9 '20 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 Dec 9 '20 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 Dec 9 '20 at 10:17
  • Anyway, it seems that I was wrong. Statistics are not written into the source file with any of the formats that I tried. – user30184 Dec 9 '20 at 10:28

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.