I would like to compute statistics for a multiband raster. How can I process?
This is my code:
python
if os.path.isfile(_tmp_path_raster):
dataset_raster = gdal.Open(_tmp_path_raster, GA_ReadOnly)
bands = dataset_raster.RasterCountount()
#doc : https://gis.stackexchange.com/questions/29064/how-to-get-gdal-to-create-statistics-for-gtiff-in-python
for band in range (1, bands+1):
band_stats = dataset_raster.GetRasterBand(band).GetStatistics(0, 1)
bd= dataset_raster.GetRasterBand(band)
bda= bd.ReadAsArray()
a=np.array(bda)
med_=np.median(a)
print(med_)
_res += str(f) + ';' + str(band_stats[0]) + ';' + str(band_stats[1]) + ';' + str(band_stats[2]) + ';' + str(band_stats[3]) + ';' + str(med_) + '\n'
and I would like to have a result like this

rasteriolibrary - or would you like to stick with the GDAL + numpy code you've shown here? – Charlie Parr Apr 04 '22 at 17:25