[gdal-dev] Zonal Grid Statistics

Rutger kassies at gmail.com
Tue Dec 18 00:06:11 PST 2018


Hey,

It may depend on the input format, but for speed you probably want to read
at least a single block at a time, not a single pixel. The blocksize can be
inspected with "gdalinfo" for example.

Calculating those statistics can be done incrementally in a single pass, so
that's certainly possible without reading all data into memory at once while
still being efficient. The wiki already provides Python code for both the
Welford algorithm and a parallel version for calculating the variance and
the mean. The min/max and sum should be trivial.

https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_Online_algorithm
<https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_Online_algorithm>  

You could consider RasterIO (a GDAL wrapper) to alleviate some of the block
related logic, but the standard GDAL Python API would also work.

Regards,
Rutger



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html


More information about the gdal-dev mailing list