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

  • 1
    'Abstract class' means you cannot instantiate it like QgsProcessingAlgorithm(..) or variable = QgsProcessingAlgorithm(). Other classes inherit from it just like class NewProcessingAlg(QgsProcessingAlgorithm) Apr 10, 2018 at 10:28
  • processing.run() See gis.stackexchange.com/a/262059/2856 and to get the input parameter syntax easily, run the alg manually and have a look at the processing history.
    – user2856
    Apr 10, 2018 at 10:55
  • @Luke ok, processing.run() seems the way to go (it felt counter-intuitive as we have QgsProcessingAlgorithm, QgsProcessingAlgRunner and many other classes). Now, any idea as to how I pipe this to my algorithm ?
    – YeO
    Apr 10, 2018 at 12:58

2 Answers 2


You can execute 'qgis:clip' in python as follows.

params = {"INPUT": inputLayer,"OVERLAY": clipLayer,"OUTPUT":clippedLayer}
processing.run(alg, params)
  • I had figured that part from a previous suggestion, now what I am trying to do is have qgis:clip take the current output of my algorithm as input and then let the final output be my algorithm output. Not sure this is clear but basically I want to call this inside my algorithm and let it return the final output... still stuck here.
    – YeO
    Apr 19, 2018 at 12:16
  • please share the code snippet of your algorithm I may be able to help you in matter.
    – Asad Abbas
    Apr 20, 2018 at 5:29
  • It's based on this template, I have just changed the logic to actually do something but I'm using the QgsProcessingFeatureSink just as in the template.
    – YeO
    Apr 20, 2018 at 11:15
  • You can try something like this clip_area = processing.runalg("qgis:clip", input_layer, clip_layer,clipped_layer) fin_area = processing.runalg("qgis:dissolve", clip_area['OUTPUT'], "true", None, processed_layer)
    – Asad Abbas
    Apr 25, 2018 at 9:50

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']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.