Skip to content

Commit b28b588

Browse files
committed
[processing] Add an example of running a sub-algorithm correctly
to script template file (cherry-picked from 9ce21e4)
1 parent 1e82e07 commit b28b588

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

python/plugins/processing/script/ScriptTemplate.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
QgsProcessingAlgorithm,
77
QgsProcessingParameterFeatureSource,
88
QgsProcessingParameterFeatureSink)
9+
import processing
910

1011

1112
class ExampleProcessingAlgorithm(QgsProcessingAlgorithm):
@@ -136,6 +137,23 @@ def processAlgorithm(self, parameters, context, feedback):
136137
# Update the progress bar
137138
feedback.setProgress(int(current * total))
138139

140+
# To run another Processing algorithm as part of this algorithm, you can use
141+
# processing.run(...). Make sure you pass the current context and feedback
142+
# to processing.run to ensure that all temporary layer outputs are available
143+
# to the executed algorithm, and that the executed algorithm can send feedback
144+
# reports to the user (and correctly handle cancelation and progress reports!)
145+
if False:
146+
buffered_layer = processing.run("native:buffer", param={
147+
'INPUT': dest_id,
148+
'DISTANCE': 1.5,
149+
'SEGMENTS': 5,
150+
'END_CAP_STYLE': 0,
151+
'JOIN_STYLE': 0,
152+
'MITER_LIMIT': 2,
153+
'DISSOLVE': False,
154+
'OUTPUT': 'memory:'
155+
}, context=context, feedback=feedback)['OUTPUT']
156+
139157
# Return the results of the algorithm. In this case our only result is
140158
# the feature sink which contains the processed features, but some
141159
# algorithms may return multiple feature sinks, calculated numeric

0 commit comments

Comments
 (0)