[Qgis-user] Raster calculator script failing for multiple rasters

R HG romanwebs at gmail.com
Tue Sep 13 02:42:09 PDT 2016


Hi,

I'm trying to do raster calculations with big and multiple rasters. I am
new to python, but I managed to use the QgsRasterCalculator algorithm to do
the average of three rasters.

The problem comes when I introduce a forth layer and try to do a more
complex equation:

#calculating c4s ( [c1-c2]*[c0-c3] )

    #F1_30
A=processing.getObjectFromUri(path + "/F1_30c1.tif")
B=processing.getObjectFromUri(path + "/F1_c2.tif")
C=processing.getObjectFromUri(path + "/F1_30c0.tif")
D=processing.getObjectFromUri(path + "/F1_c3.tif")

entries=[]
rasA=QgsRasterCalculatorEntry()
rasA.ref='A at 1'
rasA.raster=A
rasA.bandNumber=1
entries.append(rasA)

rasB=QgsRasterCalculatorEntry()
rasB.ref='B at 1'
rasB.raster=B
rasB.bandNumber=1
entries.append(rasB)

rasC=QgsRasterCalculatorEntry()
rasC.ref='C at 1'
rasC.raster=C
rasC.bandNumber=1
entries.append(rasC)

rasD=QgsRasterCalculatorEntry()
rasD.ref='D at 1'
rasD.raster=D
rasD.bandNumber=1
entries.append(rasD)

F1_30c4=QgsRasterCalculator('(( A at 1 - B at 1 ) * ( C at 1 - D at 1 ))', path +
'/F1_30c4.tif', 'GTiff', base.extent(), base.width(), base.height(),
entries).processCalculation()

I think that the problem is recognising the formula. I have tried it on the
console doing several changes and it doesnt work.

Is it possible to do this operation with QgsRasterCalculator?? Or how can I
use the gdal_calc algorithm or the saga raster calculator??


Thanks all
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20160913/e6f360e6/attachment.html>


More information about the Qgis-user mailing list