Skip to content

Commit 9ce21e4

Browse files
committed
[processing] Add an example of running a sub-algorithm correctly
to script template file
1 parent a5a91ec commit 9ce21e4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

python/plugins/processing/script/ScriptTemplate.py

+18
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):
@@ -144,6 +145,23 @@ def processAlgorithm(self, parameters, context, feedback):
144145
# Update the progress bar
145146
feedback.setProgress(int(current * total))
146147

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

0 commit comments

Comments
 (0)