[gdal-dev] removing/updating stats and histogram when editing raster

Dennis Gocke dengo at gmx.net
Fri Dec 28 07:24:09 PST 2018


Hi Even,

Thanks for the quick reply.

Regarding removing stats: I just noticed that the gdal_edit.py script also
just removes all metadata items starting with the 'STATISTICS_'. So that's
probably the way to go.

For removing the histogram there is no such option in gdal_edit.py

Your suggestion with GDALGetRasterHistogramEx() +
GDALSetDefaultHistogramEx() will not work for updating the histogram.
GDALGetRasterHistogramEx will not recompute the histogram, but instead will
fetch the existing histogram if the settings (min,max,bincount) match.
In cases the settings don't match (e.g. different max) it will compute a
new histogram and add it to the aux.xml, but the old invalid histogram will
still be there.
When GDALSetDefaultHistogramEx is called the invalid histogram will still
not be removed, but instead just the order of the histograms will be
changed.

So it seems separately (not using GDAL) removing/editing the aux.xml file
is currently the only option.
In my opinion that is a bit odd.
I think it would be good to have methods to remove statistics and
histograms.
Having those methods would also highlight that these methods need to be
explicitly called when the raster is edited and that they are not
automatically invalidated.

Another small question: Is there a GDAL config option, to make GDAL save
computed statistics to the aux.xml file instead of the raster file itself
when the raster is opened in EditMode?

Kind regards,
Dennis


Am Fr., 28. Dez. 2018 um 04:12 Uhr schrieb Even Rouault <
even.rouault at spatialys.com>:

> Dennis,
>
> > Removing:
> > If I'm not mistaken, stats can be removed by setting the
> > "STATISTICS_MINIMUM", ... Metadata Items to null, or would that only work
> > correctly for some raster formats?
> > Is there a better way to remove previously computed statistics?
> > How to remove the histogram?
>
> In most cases, stats and histographs will be in a .aux.xml sidecar file
> that
> you may just delete (or edit to remove those elements). If they are
> internal
> to the raster format, that's more difficult and you may need to translate
> it.
>
> >
> > Updating:
> > Stats can be recomputed by calling GDALComputeRasterStatistics which will
> > also update the corresponding metadata items.
> > For the histogram calling GDALGetDefaultHistogramEx with bForce=1 will
> not
> > recompute the histogram (it seems bForce is only relevant in cases where
> > the histogram has not been computed before).
> > What's the correct way to recompute the default histogram?
>
> You may use
> GDALGetRasterHistogramEx() + GDALSetDefaultHistogramEx()
>
> Even
>
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20181228/a12c4dda/attachment-0001.html>


More information about the gdal-dev mailing list