[GIS] Call output files in temporary directory through Processing Toolbox (python)

pythonqgis

I need to create temporary files as intermediate output to be used with processing algorithms. So, I implemented this:

Processing.runalgorithm("grass:v.to.rast.attribute", ........, None)

This line creates the output in C:\Users…\AppData\Local\Temp\AppData\processing\"folder"\output.tif

In this temp directory, three folders are created.

Now, I need to run other algorithm:

Processing.runAlgorithm("saga...", input,....)

The input of this is the output of the last algorithm, I am trying to access that but I can´t.

I try with system.getTempFilenameInTempFolder('output'+'.'+'tif'). But this line only access one of the three folders.

I research in http://docs.qgis.org/2.6/pt_PT/docs/user_manual/processing/console.html, and try the code presented for qgis 2.6 (but didn't work):

##dem=raster
##twi=output
ret_slope = processing.runalg("saga:slopeaspectcurvature", dem, 0, None,
                None, None, None, None)
ret_area = processing.runalg("saga:catchmentarea(mass-fluxmethod)", dem,
                0, False, False, False, False, None, None, None, None, None)
processing.runalg("saga:topographicwetnessindex(twi), ret_slope['SLOPE'],
                ret_area['AREA'], None, 1, 0, twi)

What can I do to access the output?

Best Answer

I reckon the results of any processing algorithm is a dictionary whose first element is called 'OUTPUT'. This means that calling ret_slope['SLOPE'] should instead be written as ret_slope['OUPUT']