1

I have an Int16 - 16 bit GeoTiff and would like to do a simple calculation. Using the GUI in QGIS (raster calculator) it works without problems. The expression in the raster calculator is: Raster_Image * 0.04 - 273.15

I want to do the calculation via pyqgis. For this I would like to use the process gdalogr: rastercalculator.

I tried the following:

import processing
# Get actual raster layer (GeoTiff)
layer = iface.activeLayer();
output = processing.runalg('gdalogr:rastercalculator', 
                                                layer,         #INPUT_A <ParameterRaster>
                                                '1',         #BAND_A <ParameterString>
                                                None,         #INPUT_B <ParameterRaster>
                                                '',         #BAND_B <ParameterString>
                                                None,        #INPUT_C <ParameterRaster>
                                                '',         #BAND_C <ParameterString>
                                                None,        #INPUT_D <ParameterRaster>
                                                '',         #BAND_D <ParameterString>
                                                None,        #INPUT_E <ParameterRaster>
                                                '',         #BAND_E <ParameterString>
                                                None,        #INPUT_F <ParameterRaster>
                                                '',         #BAND_F <ParameterString>
                                                'A*0.04-273.15', #FORMULA <ParameterString>
                                                '',          #NO_DATA <ParameterString>
                                                '1',           #RTYPE <ParameterSelection>
                                                '',         #EXTRA <ParameterString>
                                                None)        #OUTPUT <OutputRaster>
rLayer= QgsRasterLayer(output['OUTPUT'],'result')
print rLayer.isValid()

The calculated raster is not valid. I just do not understand what I'm doing wrong.

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.