4

In PyQGIS 2.X I could handle the output of processings algorithm as follows:

import processing
# None is the OUTPUT parameter here
buffer = processing.runalg('qgis:fixeddistancebuffer', network_from_nv_tmp, 0.1, 10, True, None)
clip = processing.runalg('qgis:clip', self.network_layer, buffer['OUTPUT'], None)

key approach here is to set the output parameter to None for running the algorithm and access it via result['OUTPUT'] in subsequent algorithms.

Now I try the same (or comparitivly the same) in PyQGIS 3:

import processing
buffer = processing.run('qgis:buffer', {'INPUT':network_from_nv_tmp, 'DISTANCE':0.1, 'SEGMENTS':10, 'END_CAP_STYLE':0, 'JOIN_STYLE':0, 'MITER_LIMIT':2, 'DISSOLVE':True, 'OUTPUT':None})        
clip = processing.run('qgis:clip', {'INPUT':self.network_layer, 'OVERLAY':buffer['OUTPUT'], 'OUTPUT':None})

which throws the following traceback:

[...]
_core.QgsProcessingException: Unable to execute algorithm
Could not create destination layer for OUTPUT: invalid value

So my question is: What is a valid value for parameter OUTPUT here?

1 Answer 1

5

I just stumbled upon a code snippet in https://anitagraser.com/2018/03/24/revisiting-point-polygon-joins/ that solved my issue. This indicates that the string 'memory:' is one possible valid value for OUTPUT parameter generating a temporary memory layer.

Furthermore, any string is a valid value. If a string e.g. 'buffered' is provided the result is stored in a Geopackage called buffered.gpkg. Thus, I strongly recommend not to provide the same string in subsequent algorithms, because the second algorithm will throw an exeption that the *.gpkg cannot be created since it has allready be created by the first.

2
  • how to do loops and use processing tools then? using 'memory:' in outputs result in a similar error message: CRITICAL There were errors executing the algorithm. 2020-02-05T10:01:47 INFO Results: {'OUTPUT': 'Buffered_8f549d26_b615_45d4_aafa_0129d2d4ed4b'} instead of Could not create layer bufferedlayer.gpkg: Creation of data source failed (OGR error: A file system object called 'bufferedlayer.gpkg' already exists.)
    – Leo
    Commented Feb 4, 2020 at 23:25
  • @Leo Interesting... I strongly recommend to ask this as a separate question! Commented Feb 6, 2020 at 7:12

Your Answer

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

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