from qgis.analysis import QgsRasterCalculator, QgsRasterCalculatorEntry import processing
from osgeo import osr, gdal from gdalconst import *
dataset1 = gdal.Open(input1, GA_Update) band1 = dataset1.GetRasterBand(1) dataset1.SetProjection( srs.ExportToWkt() ) dataset1 = None
layer1=QgsRasterLayer(dataset1,'test1')
#layer1.setCrs( QgsCoordinateReferenceSystem(3003, QgsCoordinateReferenceSystem.EpsgCrsId) )
print('load first layer')
input2='D:\\ascii2grids\\dati_ascii\\PR_2018091500UTCplus1.txt'
dataset2 = gdal.Open(input2, GA_Update) band2 = dataset2.GetRasterBand(1) dataset2.SetProjection( srs.ExportToWkt() ) dataset2 = None
layer2=QgsRasterLayer(dataset2,'test2')
print('load II layer')
exp = "%s - %s" % (layer1,layer2)
output='C:\\Users\\assis\\test.tif'
entries=[layer1,layer2]
calc = QgsRasterCalculator(exp,
output,
'GTiff',
layer1.extent,
QgsCoordinateReferenceSystem("EPSG:3003"),
layer1.width,
layer1.height,
entries
)
res = calc.processCalculation(feedback) if res == QgsRasterCalculator.ParserError:
raise QgsProcessingException(self.tr("Error parsing formula"))
This pyqgis script give me the following error:
Traceback (most recent call last): File "C:\OSGEO4~1\apps\Python37\lib\code.py", line 90, in runcode
exec(code, self.locals) File "<input>", line 1, in <module> File "<string>", line 57, in <module> TypeError: QgsRasterCalculator(): arguments did not match any overloaded call: overload 1: argument 4 has unexpected type 'builtin_function_or_method' overload 2: argument 4 has unexpected type 'builtin_function_or_method' overload 3: argument 1 has unexpected type 'str'
I do not understand the error. Perhaps the CRS definition in the QgsRasterCalculator function. Unfortunately I do not find any example of how to define CRS