In the QGIS 3.36.1 Python Console, I'm trying to create an output raster so I can write pixel values sampled from another raster.
output_raster_path = r'D:\Output Raster.tif'
output_raster = QgsRasterFileWriter(output_raster_path)
output_raster.setOutputFormat("GTiff")
output_raster.setCreateOptions([]) # No compression
output_raster.writeRaster(cols, rows, extent, input_raster.crs())
The line output_raster.writeRaster(cols, rows, extent, input_raster.crs())
is throwing an error
Traceback (most recent call last):
File "C:\OSGeo4W\apps\Python39\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 13, in <module>
TypeError: QgsRasterFileWriter.writeRaster(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'int'
overload 2: argument 1 has unexpected type 'int'
rows
and cols
are definitely int
and the extent is QgsRectangle
.
It looks like the line is right, according to the documentation:
writeRaster(self, pipe: QgsRasterPipe | None, nCols: int, nRows: int, outputExtent: QgsRectangle, crs: QgsCoordinateReferenceSystem, feedback: QgsRasterBlockFeedback | None = None) → Qgis.RasterFileWriterResult
I've tried naming the arguments, so nCols = cols, nRows = rows
etc., but that produced an error too. The error means there's something wrong with the order or type of the arguments, but I can't see what.
This is kind of similar to "QgsVectorFileWriter.writeAsVectorFormat(): arguments did not match any overloaded call" in PyQGIS but there must be a different answer.