I have a polyline layer and I want to find if a linestring is snapped to the nearest linestring or not in QGIS. How can I do that in QGIS?

I am checking for the intersection but the intersection code is not working because the line string is snapped. So I want to find the snapping linestrings.

def lines(l_layer):
    for ln1,ln2 in itertools.combinations(l_layer.getFeatures(),r=2):
        print ln1.id(),ln2.id()
        if ln1.geometry().intersects(ln2.geometry()):
            print ln1.id(),ln2.id()
            print('not intersects')

Here I am not getting one linestring which is touching with the other because it is snapped and it doesn't have the vertex. So I want to find if the line is snapped.

  • What crs are you using on your project and for both layers? – firefly-orange Sep 13 '17 at 8:53

try this:

tolerance = #insert your snapping tolerance here
if ln1.geometry().distance(ln2.geometry()) < tolerance:

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.