I am struggling to sum some rasters using QgsRasterCalculator. When the step "calc.processCalculation()" is executed, QGIS crashes with a runtime error (R6025 - pure virtual function call) or a dump.
I have a list of raster paths generated in a for loop looking like the following one. Please tell me what do I do wrong and how could I make it work...
Here is my code:
from qgis.core import *
from PyQt4.QtCore import *
from qgis.analysis import QgsRasterCalculator, QgsRasterCalculatorEntry
s1 = "E:\rcalc\OUTPUT11.sdat"
s2 = "E:\rcalc\OUTPUT22.sdat"
s3 = "E:\rcalc\OUTPUT33.sdat"
list = [s1,s2,s3]
entries = []
formula = ""
for i in range(0, len(list)):
raster = list[i]
resp = QgsRasterLayer(raster)
rast1 = QgsRasterCalculatorEntry()
rast1.raster = resp
rast1.ref = "rast"+str(i+1)
rast1.bandNumber = 1
entries.append(rast1)
rast1 = None
resp = None
if(i == len(list)-1):
formula = formula + 'rast'+str(i+1)
else:
formula = formula + 'rast'+str(i+1)+' + '
resp = QgsRasterLayer(list[0])
calc = QgsRasterCalculator( formula, "E:\output.tif", 'GTiff', resp.extent(), resp.width(), resp.height(), entries )
calc.processCalculation()