1

I have to find whether the line feature is self intersected or not.

I have tried the below logic but I am not getting it.

Is there a way to find the solution?

    lineLayerName=self.lineLayer.name()
    for ft in self.lineLayer.getFeatures():
        if ft.geometry().intersects(ft.geometry()):
            gem = ft.geometry().intersection(ft.geometry())
            intPt=gem.asPoint()
            if intPt.x() != 0 and intPt.y() != 0:
                print "Self-intersected"

If the line is self-intersected means I need the intersected point. I have attached the screenshot for reference.

Line Self-intersected

1 Answer 1

6

QgsGeometry has the isSimple() function that will return False for a line that self intersects.

lineLayerName=self.lineLayer.name()
for ft in self.lineLayer.getFeatures():
    if not ft.geometry().isSimple():
        print "Not simple - self-intersect"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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