1

I am trying to build a custom script using things I have learned from this post: Number inputs as raster calculator variables in QGIS Modeler

This is my script so far:

##Maechtigkeit unterhalb einer Hoehe=name
##Input_Raster=raster
##Hoehe = string 28.65
##Rasterout = output raster

outputs_SAGARASTERCALCULATOR_1=processing.runalg('saga:rastercalculator', Input_Raster,[],'a - Hoehe',0,False,7,Rasterout)

But I always get the error

name 'Rasterout' is not defined See log for more details

When omitting the Rasterout parameter and type None instead, it seems to run through but doesn't give me the temporary layer I need? So nothing happens really.

Is there another option for the last parameter? I tried consulting the SAGA documentation but it doesn't yield the information I need.

Also I need that output raster to do more raster calculations on.

How would I be writing that? Can I just rewrite the line:

outputs_SAGARASTERCALCULATOR_1=processing.runalg('saga:rastercalculator', Input_Raster,[],'a - Hoehe',0,False,7,Rasterout)

and use Rasterout instead of Input_Raster? And define a new Output variable'?

1 Answer 1

1

Avoid using spaces when defining parameters (excluding the name) as this can cause errors:

##Maechtigkeit unterhalb einer Hoehe=name
##Input_Raster=raster
##Hoehe=string 28.65
##Rasterout=output raster
4
  • Thanks for your answer. However, I am confused; which spaces do you mean? "output raster" has a required space without which this parameter will not be available the user. docs.qgis.org/2.14/en/docs/user_manual/processing/scripts.html
    – The Dude
    Feb 8, 2019 at 12:39
  • @S.Kuske - I meant when you give a name to a parameter. So anything to the left of the = sign should not contain any white spaces. E.g. ##Input Raster=raster will not work; ##Input_Raster=raster will work.
    – Joseph
    Feb 8, 2019 at 12:43
  • Alright thanks. The original error went away after deleting all the spaces. No I am getting a - 'NoneType' object has no attribute 'crs' See log for more details - Error. In both cases, when I want to save it to a file in a directory or leaving it blank and supposedly creating a temporary file, which is actually what I need when trying to move on from here.
    – The Dude
    Feb 8, 2019 at 12:50
  • 1
    @S.Kuske - I think you should ask this as a new question as StackExchange has a policy of one post per question :)
    – Joseph
    Feb 8, 2019 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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