2

I am using QGIS 2.18.15.

I want to streamline multiple SAGA raster calculator calculations using the output of one calculation (not loading it into the table of contents) as input raster for the next and so one. I found some useful things at Pipe output of one processing algorithm as input into another algorithm in QGIS 2.18 Processing script and in the QGIS doc here.

I built a script looking like this:

##MaechtigkeitunterhalbeinerHoehe=name
##Input_Raster=raster
##Hoehe= string 28.65
##Pos_Differenzen=output raster

formula='a-{}'.format(Hoehe)

Differenzen=processing.runalg('saga:rastercalculator',Input_Raster,[],formula,0,False,7,None)

Pos_Differenzenalg=processing.runalg('saga:rastercalculator', Differenzen['Result'],[],'a*(a>0)',0,False,7,Pos_Differenzen)

As you can see I am trying to access the output of "Differenzen" by using Differenzen['Result'] as the input parameter for "Pos_Differenzen". When I define an output rater parameter like ## Differenzenout=output rasterit at least generates no error through the first part, but it load the result into the table of content (which I am trying to avoid) and also gives me an error for the second part. I have also tried 'OUTPUT' instead of 'RESULT'but to no avail. If I run the second algorithm on its own with the previously calculated temporary raster from the Diffrenzen algorithm as ##Input_raster it works fine again.

What am I doing wrong?

1 Answer 1

3

You should use capital letters for the RESULT which is the Key in the dictionary 'Differenzen':

Pos_Differenzenalg=processing.runalg('saga:rastercalculator', Differenzen['RESULT'],[],'a*(a>0)',0,False,7,Pos_Differenzen)
3
  • Why is it always the little things?! Thank you so much! It worked!
    – The Dude
    Feb 13, 2019 at 8:14
  • Hab gerade erst gesehen, dass es du ja wieder warst, Stefan ^^. Vielen Dank, dass du meiner Bitte nachgekommen bist.
    – The Dude
    Feb 13, 2019 at 8:15
  • It works but it still shows > "Wrong parameter value: C:\Users\saku\AppData\Local\Temp\processing2bd0c9ce76084b92b2e46ef30e6e930d\e53ef4ff6b4e440fb09e24fcbdf640f9\RESULT.sdat" in the Python console and I cannot save to file (nothing at all happens)
    – The Dude
    Feb 13, 2019 at 9:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.