Thursday 18 June 2015

pyqgis - Calling a QgsProcessingAlgorithm from a Processing python script in QGIS 3.0?


I am writing a Processing python script based on the template provided here.


I am creating lines (destined to the 'OUTPUT') and I would like to clip them according to a polygon entered as the 'INPUT' parameter). I can't figure out how to call the Algorithm. For what it's worth, this doesn't work:
QgsProcessingAlgorithm('qgis:clip').run({'INPUT': self.OUTPUT, 'OVERLAY': self.INPUT})


I have tried several ways but couldn't get far as I get the error: qgis._core.QgsProcessingAlgorithm represents a C++ abstract class and cannot be instantiated



Answer



I have found the following to work:



temp = QgsVectorLayer('Line', 'temp', 'memory')
# do some stuff with temp
clipped_lines = processing.run('native:clip', {
'INPUT': temp,
'OVERLAY': parameters['INPUT'],
'OUTPUT': 'memory:ClippedLines',
}, context=context, feedback=feedback)['OUTPUT']

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...