[GIS] Intersecting two polylines using ArcObjects

arcobjectsintersectiontopology

I have two polylines and would like to find the intersection(s) using ArcObjects / VB.NET.

I'm using the following code:

Dim topoOp As ITopologicalOperator = TryCast(pTestPoly2, ITopologicalOperator)
topoOp.Intersect(TryCast(pTestPoly1, IGeometry), ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry0Dimension)
Dim pOutPointCol As IPointCollection = TryCast(topoOp, IPointCollection)

In the resulting IPointCollection I get all the vertices of the input pTestPoly2, although there should be one intersection of the two polylines.

What's wrong with this approach?

Best Answer

Use the return value of the Intersect method instead of the TopologicalOperator. Try the following instead (I use C#, not VB.NET, so hopefully this works. The casting business is really confusing):

Dim topoOp As ITopologicalOperator = TryCast(pTestPoly2, ITopologicalOperator)
Dim pOutPointCol As IPointCollection = TryCast(topoOp.Intersect(TryCast(pTestPoly1, IGeometry), ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry0Dimension), IPointCollection)
Related Question