Skip to content
Permalink
Browse files

[processing] Add an example of running a sub-algorithm correctly

to script template file
  • Loading branch information
nyalldawson committed Apr 27, 2018
1 parent a5a91ec commit 9ce21e4a828a3e9677a9219132711d75fa83dda3
Showing with 18 additions and 0 deletions.
  1. +18 −0 python/plugins/processing/script/ScriptTemplate.py
@@ -6,6 +6,7 @@
QgsProcessingAlgorithm,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink)
import processing


class ExampleProcessingAlgorithm(QgsProcessingAlgorithm):
@@ -144,6 +145,23 @@ def processAlgorithm(self, parameters, context, feedback):
# Update the progress bar
feedback.setProgress(int(current * total))

# To run another Processing algorithm as part of this algorithm, you can use
# processing.run(...). Make sure you pass the current context and feedback
# to processing.run to ensure that all temporary layer outputs are available
# to the executed algorithm, and that the executed algorithm can send feedback
# reports to the user (and correctly handle cancelation and progress reports!)
if False:
buffered_layer = processing.run("native:buffer", param={
'INPUT': dest_id,
'DISTANCE': 1.5,
'SEGMENTS': 5,
'END_CAP_STYLE': 0,
'JOIN_STYLE': 0,
'MITER_LIMIT': 2,
'DISSOLVE': False,
'OUTPUT': 'memory:'
}, context=context, feedback=feedback)['OUTPUT']

# Return the results of the algorithm. In this case our only result is
# the feature sink which contains the processed features, but some
# algorithms may return multiple feature sinks, calculated numeric

0 comments on commit 9ce21e4

Please sign in to comment.
You can’t perform that action at this time.