I am teaching myself pyqgis and try to find those polygons in one layer that intersect with polygons in another layer. It seems very trivial, and on GIS.SE are several similar questions that are suggesting me (with my limited python/pyqgis-knowledge) that this should work:
#ausschluss and gebaeude are QgsVectorLayers with Polygons #(shapefiles with the same crs and clearly intersecting) gebaeude.setSelectedFeatures() #deselects everything selections= #declares it is a list for f in gebaeude.getFeatures(): for a in ausschluss.getFeatures(): if a.geometry().intersects(f.geometry()): #same result with .within() and even with a and f switched (the docs aren't that clear on that) selections.append( f.id() ) break #only one or less intersection are possible gebaeude.setSelectedFeatures(selections) gebaeude.invertSelection() #gives 0, 78137 an 78137 (no intersection found) print len(selections) print gebaeude.selectedFeatureCount() print gebaeude.featureCount()
What is it, I am doing wrong?
Edit: Running QGis 2.8.3 on OS X (10.8.5) with the KyngChaos-Longterm-Built