Skip to main content
2 of 3
deleted 1 character in body
xunilk
  • 30.2k
  • 4
  • 43
  • 82

I got my system dump with your code. Issue is because it's necessary a good reference for your layer by using QgsRasterCalculatorEntry class methods (you cannot use that string for 'expression'). So, with a copy/path of your next modified code at Python Console of QGIS:

l=iface.activeLayer()
a=l.extent()
b=l.width()
c=l.height()
from qgis.analysis import QgsRasterCalculator, QgsRasterCalculatorEntry
rast = QgsRasterCalculatorEntry()
rast.ref = l.name() +'@1'
rast.raster = l
rast.bandNumber = 1
entries=[ rast ]

expression = '( ' + entries[0].ref + ' ) * 200 '
print expression

calc = QgsRasterCalculator( expression,
                            "/home/zeito/pyqgis_data/z.tif",
                            'GTiff',
                            a,
                            b,
                            c,
                            entries )

calc.processCalculation()  

I got 0 execution code, pointed out that it ran without problems. I tried it out with raster of next image (with only 3 values to make corroboration easier).

enter image description here

By using Value Tool plugin, it was corroborated that values were obtained as expected in resulting raster.

xunilk
  • 30.2k
  • 4
  • 43
  • 82