[gdal-dev] gdalinfo -mm also report n (number of grid cells that are not nodata)
Even Rouault
even.rouault at spatialys.com
Sat Jun 16 13:00:22 PDT 2018
>
> I checked, results with gdalinfo -stats are wrong because existing
> STATISTICS_* metadata are reported even if approximate statistics are not
> allowed.
No, if STATISTICS_APPROXIMATE=YES and is set in .aux.xml (because initial
computation was done with -approx_stats) and you do gdalinfo -stats after,
then statistics will be recomputed on all samples and
STATISTICS_APPROXIMATE=YES will be cleared
Demo:
$ gdalinfo -approx_stats test.tif
[...]
Metadata:
STATISTICS_APPROXIMATE=YES
STATISTICS_MAXIMUM=206
STATISTICS_MEAN=126.17083333333
STATISTICS_MINIMUM=74
STATISTICS_STDDEV=21.548781465291
$ gdalinfo -stats test.tif
[...]
Metadata:
STATISTICS_MAXIMUM=255
STATISTICS_MEAN=126.765
STATISTICS_MINIMUM=74
STATISTICS_STDDEV=22.928470838676
> The problem is, STATISTICS_APPROXIMATE is not set. Other software
> using GDAL to create raster datasets may use
> GDALRasterBand::SetStatistics() which does not indicate if stats are
> approximations., i.e. stats are approximations but there is no
> STATISTICS_APPROXIMATE=YES.
The idea is that if you use GDALRasterBand::SetStatistics() then you are
assumed to provide exact statistics. If they are only approximate, then you
should also set STATISTICS_APPROXIMATE=YES with GDALSetMetadataItem()
>
> GDAL assumes that STATISTICS_* metadata represent stats on all pixels, this
> is IMHO wrong. You can only hope that STATISTICS_* metadata represent stats
> on all pixels if a respective metadata item has been set to boolean true,
> something like STATISTICS_ALL_PIXELS=YES.
I'm really confused. Why introducing yet another item whereas
STATISTICS_APPROXIMATE=YES is there for that purpose ?
> Even in this case, an option to
> force recomputing raster band stats would be very nice to have (verifying
> metadata).
ComputeStatistics() will recompute statistics. It is true that with gdalinfo -
stats, they are not recomputed if they already exist and were not approximate
since it calls GetStatistics() and not ComputeStatistics(). An easy workaround
is to delete the .aux.xml to force recomputation.
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list