I have a drains layer (polygon) around which I have created buffers of varying distances. I want to find the intersection between the different buffer layers and pipes (line) layer and accordingly assign score in a field. I have used the following code:
pathName = os.path.dirname(unicode(drainLayer.dataProvider().dataSourceUri())) waterLayer.startEditing() for filename in os.listdir(pathName): if filename.endswith('1.shp') and ('buf' in filename): #name = ntpath.basename(filename).split('.') buf = QgsVectorLayer(pathName,filename,"ogr") for f1 in waterLayer.getFeatures(): for f2 in buf.getFeatures(): if f1.geometry().intersects(f2.geometry()): f1['drainScore']=3 waterLayer.updateFeature(f1) waterLayer.commitChanges() for filename in os.listdir(pathName): if filename.endswith('2.shp') and ('buf' in filename): #name = ntpath.basename(filename).split('.') buf2 = QgsVectorLayer(pathName,filename,"ogr") for f1 in waterLayer.getFeatures(): for f2 in buf2.getFeatures(): if (f1.geometry().crosses(f2.geometry())): f1['drainScore']=2 waterLayer.updateFeature(f1) else: f1['drainScore'] =1 waterLayer.updateFeature(f1)
Wherever the intersections are complete it gives the correct output. But wherever there are partial intersections, it does not identify them. I have used crosses,touches and intersects method in the second
I have also tried processing algorithms like
qgis:joinattributesbylocation (with crosses as
PREDICATE) but none of them recognize partial intersections. When I use the vector tools of intersection and join attributes by location from QGIS 3 desktop, it gives the correct output, i.e., it recognizes partial as well as complete intersection. I have attached an image of the kind of partial intersection I want the code to recognize.