2

I want to run the process "qgis:intersection" in a pyton-script and try it like this:

import processing
a1 = QgsMapLayerRegistry.instance().mapLayersByName('Layer1')[0]
a2 = QgsMapLayerRegistry.instance().mapLayersByName('Layer2')[0]
processing.runandload("qgis:intersection", a1, a2, "memory:myCut")

But there comes the "Problem executing algorithm" message: "GEOS geoprocessing error: One or more input features have invalid geometry."

If i do the same by the qgis-gui (Vector/Geoprocessing Tools/Intersect...) in QGIS 2.14.21 like this: enter image description here

then everything is ok and qgis do the intersection.

Doing the intersectin with QGIS 2.18.13 with the gui, I become also an error like above.

"Layer2" is a large layer with some hundredthousands polygons an if i use the "Topology Checker" i get about 600 invalid geometries.

Why does the intersection work only with the qgis-gui in 2.14.21 and not somewhere else?

  • 1
    I would assume the code used for most spatial analysis tools would have been improved between the two QGIS versions you mentioned. The earlier one probably didn't check for invalid geometries. In 2.18, there is the optional Ignore NULL geometries setting which you could use when you run your script and see if it works: processing.runandload("qgis:intersection", a1, a2, True, "memory:myCut") – Joseph Dec 18 '17 at 10:02
  • In 2.18.13 I have already tried "processing.runandload("qgis:intersection", a1, a2, True, "memory:myCut")", but there is still the error. But why works the process with the gui in 2.14? – vezzon Dec 18 '17 at 10:07
  • One way to get around this problem is using "saga:intersect" as it will not complain about the invalid geometries – xlDias Dec 18 '17 at 11:18
0

Thank you xlDias, "saga:intersect" solved the Problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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