6

I have a processing script which chains together several saga processing tools like this:

outputs_SAGARASTERCALCULATOR_3=processing.runalg('saga:rastercalculator', inputvx,[inputvy],'(atan2(a,b)) * (180/pi())',True,7,None)
outputs_SAGAGRIDVALUESTOPOINTS_1=processing.runalg('saga:gridvaluestopoints', [outputs_SAGARASTERCALCULATOR_3['RESULT'],PolygonExtent,None,True,0,OutputName)

The calculator process defaults to calling the raster calculator output'RESULT', which means it ends up using the same interim file when you run a batch process - they are all called result regardless of the inputs.

How do I change the name of the calculation result to be something other than 'result'?

Here's the python console for the calculator tool - I assume I can alter both 'Result:' and 'Name:' but it won't seem to allow me to add any other parameters into the tool.

        Grid system: 10; 2601x 1500y; 383472.948554x 557408.826780y
        Grids: 1 object (Tyne10mBaselineUpdated02MainFlood0100Vx)
        Grids from different Systems: 1 object (Tyne10mBaselineUpdated02MainFlood0100Vy)
        Result: Result
        Formula: (atan2(a,b)) * (180/pi())
        Name: Calculation
        Take Formula: no
        Use NoData: yes
        Data Type: 4 byte floating point number
3

A possible workaround could be to add the following line at the end of your script which will load the output file with the filename you gave it:

iface.addVectorLayer(OutputName, os.path.splitext(os.path.basename(OutputName))[0], "ogr")

So your script could look like:

outputs_SAGARASTERCALCULATOR_3=processing.runalg('saga:rastercalculator', inputvx,[inputvy],'(atan2(a,b)) * (180/pi())',True,7,None)
outputs_SAGAGRIDVALUESTOPOINTS_1=processing.runalg('saga:gridvaluestopoints', outputs_SAGARASTERCALCULATOR_3['RESULT'],PolygonExtent,None,True,0,OutputName)

iface.addVectorLayer(OutputName, os.path.splitext(os.path.basename(OutputName))[0], "ogr")

# Or you can give it any name using the line below
# iface.addVectorLayer(OutputName, "anyName", "ogr")

Note:

  1. This will only work if you uncheck the Open output file after running algorithm option in the script interface.

  2. You may have to include the following in your script:

    import os
    from qgis.utils import iface
    

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.