Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

If I have a polyline, how do I figure out whether it is self-intersecting? I tried to use ITopologicalOperator.IsSimple Property, but it always returns true.

Are there any ways of doing these kind of topological checks over individual geometries?

share|improve this question
    
As a last resort you can split polyline into segments, and check intersection between each segment, but this should be done only if there is no other way to do that, because it most likely will be quite slow. –  Sunder Nov 20 '12 at 10:44

2 Answers 2

up vote 3 down vote accepted

I think you can do with with the ITopologicalOperator2 interface:

dim pTopoLogicalOp as ITopologicalOperator2
Set pPolyline = pFeature.ShapeCopy
Set pTopoLogicalOp = pPolyline
Let pTopoLogicalOp.IsKnownSimple = False
If pTopoLogicalOp.IsSimple = False Then
   ' Polyline is self intersecting
End If
share|improve this answer
    
doesn't work. pTopoLogicalOp.IsSimple is always true –  Devdatta Tengshe Nov 20 '12 at 10:57
    
I played around a little bit more, and found that your code works in VBA, but the corresponding code in C# still gives IsSimple as true. There are also quite a few issues mentioned with ITopologicalOperator, so we'll have to chalk it down to that. –  Devdatta Tengshe Nov 20 '12 at 11:38

The Polyline should be converted to a Polygon, and then the ITopologicalOperator3:get_IsSimpleEx() method can be used

Here is the sample code

private bool IsLineSelfIntersecting(IPolyline line)
    {
        bool isSelfIntersecting = false;

        IPointCollection polygonVertices = new PolygonClass();
        IPointCollection lineVertices = line as IPointCollection;

        polygonVertices.AddPointCollection(lineVertices); //convert to Polygon

        ITopologicalOperator3 topo = polygonVertices as ITopologicalOperator3;
        esriNonSimpleReasonEnum reason =esriNonSimpleReasonEnum.esriNonSimpleSelfIntersections;
        topo.IsKnownSimple_2 = false;
        if (!topo.get_IsSimpleEx(out reason))
        {
            if (reason == esriNonSimpleReasonEnum.esriNonSimpleSelfIntersections)
            {
                isSelfIntersecting = true;
            }
        }

        return isSelfIntersecting;
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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