I want to count intersections between two line layers using pyqgis. First layer connects two points (Memorylayer_VL / Connections), the second one represents streets (lines_layer / Streets). I need to figure out how many times Connectionlines intersects with a Street. Note that the streets can have curves. So I also need to count, if a line crosses the same street more than once!
Thats where I am struggling to find a good logic how I could implement this. Anyone has a brilliant idea how this could be done? Thats what I have so far... It only counts if a street has been crossed, but not how many times.
for tmp_line_feat in Memorylayer_VL.getFeatures():
for streets in lines_layer.getFeatures():
counter = 0
if tmp_line_feat.geometry().intersects(streets.geometry()):
counter = counter + 1
attr = {5:counter}
Memorylayer_PR.changeAttributeValues({ tmp_line_feat.id() : attr })
Example:
I need to know for each connection line, how many times a street has been crossed.