I cannot find the exact python syntax for saga:intersect anywhere. The following throws "Could not load source layer for A: no value specified for parameter". It prints

laender = QgsProject.instance().mapLayersByName('laenderpolygone')[0]
laender.selectByExpression('"LAND" LIKE \'RP\'')
iface.addVectorLayer(r'%s/index_merged.gpkg' % proj, "index_merged", "ogr")
index_merged = QgsProject.instance().mapLayersByName('index_merged')[0]

processing.run("saga:intersect", {'SHAPES': laender, 'SHAPES_1': index_merged, 'RESULT': r'D:\path\QGIS\vrt\intersect.gpkg'})

This is related to Executing intersect algorithm with pyqgis?.

Another option would be to change the processing parameters to ignore the bad geometry warning that I get when doing the QGIS intersect. How would that be done?

  • 2
    "This does not seem to work" isn't helpful in a question. You should explain what doesn't work. Does it throw an error? Does it return an empty result? Something else. Be more explicit. Commented May 5, 2023 at 10:58

2 Answers 2


For future problems with the syntax of specific algos you want to trigger with processing.run(algo, params):

When you run an algorithm manually from the toolbox, you will get the used dictionary with the params in the protocol of the running algorithm. Just copy it, change the values and have fun with it :)


The syntax is

processing.run("saga:intersect", {'A': index_merged, 'B': laenderPoly, 'selectedFeaturesOnly': 'True', 'featureLimit':-1, 'SPLIT': True, 'RESULT': r'%s/intersect.gpkg'%proj})

However, the result is inverted, i.e. the resulting shape is everything of index_merged that doesn't intersect with the selected feature from laenderpoly. Maybe still some syntax error? I used the same parameters as printed by the log of the GUI tool, where it worked, but of course it gives you the command line syntax, not python... It also works saving the selected feature as a new shapefile and using that for intersection as a workaround, but it would be nice to get the direct solution.

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.