Skip to content

Commit

Permalink
[processing] Add an example of running a sub-algorithm correctly
Browse files Browse the repository at this point in the history
to script template file
  • Loading branch information
nyalldawson committed Apr 27, 2018
1 parent a5a91ec commit 9ce21e4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/plugins/processing/script/ScriptTemplate.py
Expand Up @@ -6,6 +6,7 @@
QgsProcessingAlgorithm,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink)
import processing


class ExampleProcessingAlgorithm(QgsProcessingAlgorithm):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9ce21e4

Please sign in to comment.