<div dir="auto"><div>Laurent and list,<br><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, Dec 23, 2025, 15:23 celati Laurent via QGIS-User <<a href="mailto:qgis-user@lists.osgeo.org">qgis-user@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Good afternoon, </div><div><br></div><div>I work with Qgis 3.40. </div><br>I have a question almost similar to <a href="https://gis.stackexchange.com/questions/338888/calculating-the-average-of-multiple-bands-of-raster-with-high-number-of-bands-in" target="_blank" rel="noreferrer">this post</a>. But i would like to caculate the median instead of the average/median. From one single raster with 90 bands, i would like generate a new raster file with the median value for each pixel. The median has to be calculated from all the 90 bands for each pixel.<br><br>Following still <a href="https://gis.stackexchange.com/questions/338888/calculating-the-average-of-multiple-bands-of-raster-with-high-number-of-bands-in" target="_blank" rel="noreferrer">this post </a>succeed in calculating the average from the 90 bands thanks to this following python qgis script : <br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">    rasterlayer = QgsProject.instance().mapLayersByName('infra-red')[0] #Change infra-red to the name of your layer<br>    bandcount = rasterlayer.bandCount() #Count the bands<br>    <br>    tempexp = ['"{0}@{1}"'.format(<a href="http://rasterlayer.name" target="_blank" rel="noreferrer">rasterlayer.name</a>(), bandnum) for bandnum in range(1,bandcount+1)] #['"infra-red@1"', '"infra-red@2"', '"infra-red@3"', '"infra-red@4"']<br>    tempexp = '+'.join(tempexp) #'"infra-red@1"+"infra-red@2"+"infra-red@3"+"infra-red@4"'<br>    exp = '('+tempexp+')/{0}'.format(bandcount) #'("infra-red@1"+"infra-red@2"+"infra-red@3"+"infra-red@4")/4'<br>    <br>    processing.runAndLoadResults("qgis:rastercalculator", <br>        {'EXPRESSION':exp,'LAYERS':[rasterlayer.source()],'CELLSIZE':None,'EXTENT':None,'CRS':None,'OUTPUT':'TEMPORARY_OUTPUT'})</blockquote><br>Is there a way to do the same thing but this time to calculate the median value ? <br></div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Not sure of the actual expression but if you can sort the list ¿? created in the join step then you must extract elements 45 and 46 and take their average to get the median of a list with 90 elements.</div><div dir="auto"><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer noreferrer" target="_blank"></a><br>
</blockquote></div></div></div>