Raster calculator is not working correctly for a single calculation using a standalone Python script. I am trying to add 1 to a pre-existing raster. It processes, but the resulting tiff file is all 0s. I have used similar code for other rasters and calculations which work, but this one does not.

entries = []
Layer1 = QgsRasterLayer('input.tif', "Lyr1")
print(Layer1.isValid()) # it is valid
ras = QgsRasterCalculatorEntry()
ras.ref = 'lyr1@1'
ras.raster = Layer1
ras.bandNumber = 1

calc = QgsRasterCalculator('"lyr1@1"+1', 'output.tif', 'GTiff', \
Layer1.extent(), Layer1.width(), Layer1.height(), entries)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.