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.
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?