2

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?

3
  • There's a double-quotation mark missing in the third process saga:topographicwetnessindex(twi). Might not fix the problem though. – Joseph Jan 7 '15 at 15:40
  • I don't understand what are you refered to. What is missing? Can you confirm that ret_slope['SLOPE'] and ret_area['AREA'] are the correct way to call the outputs? Because I try also and it doesn't work. – Bárbara Duarte Jan 7 '15 at 16:00
  • Welcome to gis.stackexchange! Please reword the title of your thread to contain enough information for future readers who might be looking for the same information – underdark Jan 7 '15 at 17:41
2

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']

1

I am no expert in this field but I tend to find it easier to "name" each algorithm I use such as the following:

outputs_1=processing.runalg("qgis:fieldcalculator", Layer, ............, None)
outputs_2=processing.runalg("qgis:deletecolumn", outputs_1, ..........., Result)

Doing this should allow you to ignore typing in the location of where the temporary files are stored and their filename.

Hope this helps!

5
  • I try that option but gives me nothing also. – Bárbara Duarte Jan 7 '15 at 10:59
  • If you know exactly where the file is, you can include the file location into your code. Eg, in your second example, replace input with "C:\Users...\AppData\Local\Temp\AppData\processing\"folder"\output.tif". Note the quotes. – Joseph Jan 7 '15 at 11:05
  • I know the directory but the folder where the file is created is always different and it is automatically created. It is like this:"C:\Users...\AppData\Local\Temp\AppData\processing\addaf198a04e4c2da465a75d8bc88320\output.tif". If I run again the folder created has another name and so on, and so on,... – Bárbara Duarte Jan 7 '15 at 11:15
  • The other alternative I can think of is to save the outputs in a specific directory instead of creating temporary files. Then use that directory in the code, you can always delete the outputs manually or use python. Apologies but hopefully others can provide a definitive answer for you! – Joseph Jan 7 '15 at 11:23
  • Thanks anyway. I try that option, I save the files in a directory and I try to remove in the end but gives me error. So, I think the best option is to create temporary files. Thanks anyway. – Bárbara Duarte Jan 7 '15 at 11:24

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.