I am trying to clip streets by a layer with municipalities in them. I was trying to run this script in QGIS3 but obtain the error hereunder.

Traceback (most recent call last): File "C:\OSGEO4~1\apps\Python37\lib\code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in File "", line 11, in File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\tools\general.py", line 105, in run return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context) File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\core\Processing.py", line 130, in runAlgorithm context = dataobjects.createContext(feedback) File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\tools\dataobjects.py", line 72, in createContext context.setFeedback(feedback) TypeError: QgsProcessingContext.setFeedback(): argument 1 has unexpected type 'str'

I tried to run the script in QGIS2 and it works perfectly (changing run to runalg off course).

I checked the documentation of clipping in PyQGIS3 but I can't figure out what I am doing wrong. I hope someone has some insights for me.

import processing

streets = QgsVectorLayer(r"C:\Users\Me\Desktop\Test\\streets_fix.shp", "streets", "ogr")
if not streets.isValid():
  print("Layer failed to load!")

municipalities= QgsVectorLayer(r"C:\Users\Me\Desktop\Test\municipalities.shp", "municipalities", "ogr")
if not municipalities.isValid():
  print("Layer failed to load!")

processing.run("qgis:clip", municipalities, streets, r"C:\Users\Me\Desktop\Test\clipttest1.shp")

1 Answer 1


The way how the parameters will be passed has changed in QGIS3, see https://docs.qgis.org/testing/en/docs/user_manual/processing/console.html

in your case it should be:

processing.run("qgis:clip", {'INPUT': streets,'OVERLAY': municipalities, 'OUTPUT': 'C:/Users/Me/Desktop/Test/clipttest1.shp'})

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.