Good afternoon, I work with Qgis 3.40.
I have a question almost similar to this post <https://gis.stackexchange.com/questions/338888/calculating-the-average-of-multiple-bands-of-raster-with-high-number-of-bands-in>. 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. Following still this post <https://gis.stackexchange.com/questions/338888/calculating-the-average-of-multiple-bands-of-raster-with-high-number-of-bands-in>succeed in calculating the average from the 90 bands thanks to this following python qgis script : rasterlayer = QgsProject.instance().mapLayersByName('infra-red')[0] > #Change infra-red to the name of your layer > bandcount = rasterlayer.bandCount() #Count the bands > > tempexp = ['"{0}@{1}"'.format(rasterlayer.name(), bandnum) for > bandnum in range(1,bandcount+1)] #['"infra-red@1"', '"infra-red@2"', > '"infra-red@3"', '"infra-red@4"'] > tempexp = '+'.join(tempexp) #'"infra-red@1"+"infra-red@2"+"infra-red@3 > "+"infra-red@4"' > exp = '('+tempexp+')/{0}'.format(bandcount) #'("infra-red@1 > "+"infra-red@2"+"infra-red@3"+"infra-red@4")/4' > > processing.runAndLoadResults("qgis:rastercalculator", > > {'EXPRESSION':exp,'LAYERS':[rasterlayer.source()],'CELLSIZE':None,'EXTENT':None,'CRS':None,'OUTPUT':'TEMPORARY_OUTPUT'}) Is there a way to do the same thing but this time to calculate the median value ? Thanks so much. Regards.
_______________________________________________ QGIS-User mailing list [email protected] List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
