1

I'm writing a plugin, where self.dlg.lineEdit_11.text() This number (attached image)

enter image description here

gives an error message

Traceback (most recent call last): calc = QgsRasterCalculator("rastr_raznica1@1" + s, var, 'GTiff', layer2.extent(), layer2.width(), layer2.height(), entries ) TypeError: cannot concatenate 'str' and 'float' objects

through processing, I appeal to the raster calculator, but he does not want to be considered QgsRasterCalculator("rastr_raznica1@1" + s) It does not take s the number

def edit_raster(self):
    entries =[]
    rastrway1=self.dlg.lineEdit_11.text()
    var= os.path.join(os.path.abspath(os.path.dirname(rastrway1)),'rastr_sko.tif')
    tif2=  os.path.join(os.path.abspath(os.path.dirname(rastrway1)),'rastr_raznica1.tif')
    r = self.dlg.lineEdit_10.text()
    s=float(r)
    print s
    layer2 = QgsRasterLayer(tif2, "rastr_sko")
    her_2 = QgsRasterCalculatorEntry()
    her_2.ref = 'rastr_raznica1@1'
    her_2.raster = layer2
    her_2.bandNumber = 1
    entries.append(her_2)
    calc = QgsRasterCalculator("rastr_raznica1@1" + s, var, 'GTiff', layer2.extent(), layer2.width(), layer2.height(), entries )
    calc.processCalculation()
  • 1
    Welcome to GIS:SE @zhora! Try replacing s=float(r) with s=str(r) and then replace "rastr_raznica1@1" + s with "rastr_raznica1@1 +" + s. – Joseph Feb 17 '17 at 9:56
  • The whole input to rastercalculator needs to be quoted, but also the rasterbands. Not sure if you have double quotes there or two times single ones. with double quotes it should look like: ""rastr_raznica1@1"+{}".format(s) – Matte Feb 17 '17 at 11:04

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.