[Qgis-user] Qgis : Calculat the median of multiple bands of raster (90 bands)

Karlo no Dabas maajas karlo at latnet.lv
Thu Jan 1 07:50:28 PST 2026


Hi again!

„Focal Statistics” works only with one layer. But it's easy to overcome 
this with small script.

Look at this example. As the source, I have a GeoTIFF with 6 bands:

$ gdalinfo MultidimensionGrid.tif | grep Band
Band 1 Block=1830x1 Type=UInt16, ColorInterp=Gray
Band 2 Block=1830x1 Type=UInt16, ColorInterp=Undefined
Band 3 Block=1830x1 Type=UInt16, ColorInterp=Undefined
Band 4 Block=1830x1 Type=UInt16, ColorInterp=Undefined
Band 5 Block=1830x1 Type=UInt16, ColorInterp=Undefined
Band 6 Block=1830x1 Type=UInt16, ColorInterp=Undefined
Band 7 Block=1830x1 Type=UInt16, ColorInterp=Undefined


So I create a script to calculate median for all bands:

____________________________________________________
for NR in {0..5} ; do
	echo Band $NR
	saga_cmd io_gdal 0 \
		-GRIDS MultiDim$NR -MULTIPLE 0 \
		-SELECTION  $NR \
		-FILES MultidimensionGrid.tif
	saga_cmd statistics_grid 1 \
		-GRID MultiDim$NR.sgrd  \
		-MEDIAN Median$NR
	rm MultiDim$NR.*
done
___________________________________________________

Best regards,
Kārlis



01.01.26 11:49, Karlo no Dabas maajas via QGIS-User rakstīja:
> Happy New Year!
> 
> I suppose the module from SAGA-GIS „Focal Statistics” should do this.
> 
> Best regards,
> Kārlis
> 
> 31.12.25 14:32, Andrea Giudiceandrea via QGIS-User rakstīja:
>>> Karlo no Dabas maajas karlo at latnet.lv
>>> Tue Dec 30 02:04:43 PST 2025
>>> Why not to use SAGA or GRASS? You can use them as stand alone or from 
>>> QGIS.
>>
>> Hi Kārlis,
>> what SAGA-GIS or GRASS processing algorithms in QGIS are able to 
>> calculate the median value among multiple bands stored in a single 
>> raster layer?
>> [..]
> _______________________________________________
> QGIS-User mailing list
> QGIS-User at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


More information about the QGIS-User mailing list