[QGIS-Developer] How to get estimated raster statistic without calc them?

Luigi Pirelli luipir at gmail.com
Fri Jan 18 04:56:08 PST 2019

Hi devs

I face a (IMHO) an API limitation that I'm not sure is a limitation of a
feature :)

I'm working adding SLD export for rasters as new feature and some
stretching (QgsContrastEnhancement) should be mapped differently if the
min/max values has been modified from the real min/max of the image.

This can be simply asked to the raster with QgsRasterLayer.statistic(<band
number>). The main problem I'm faced is that if statistic is not present it
is ALWAYS calculated.
This means that if we have big images or a remote one (e.g. COG) this would
take long time!
I do not analysed any raster provider, but I suppose that min/max values
can be estimated asking to raster metadata.

IMHO we can have an API like
QgsRasterLayer.estimatedStatistic(<band number>)
QgsRasterLayer.statistic(<band number>, estimated=false)

that can return metadata values if available.

The proposal is valid if there is no a method to get estimated statistic,
but I could be wrong and that's the reason of this post.

Luigi Pirelli

p.s. remember to come to 2019.qgis.es ;) we'll open inscription next monday!

* LinkedIn: https://www.linkedin.com/in/luigipirelli
* Stackexchange: http://gis.stackexchange.com/users/19667/luigi-pirelli
* GitHub: https://github.com/luipir
* Mastering QGIS 2nd Edition:
* Hire me: http://goo.gl/BYRQKg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190118/e7c8df24/attachment.html>

More information about the QGIS-Developer mailing list