4

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?

1 Answer 1

7

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)
2
  • 3
    +1 Also it is common practice to make sure both geometries have spatial reference and have been simplified (via ITopologicalOperator.Simplify). Commented Nov 16, 2011 at 3:52
  • Thanks, it works great! It is a bit confusing, though. Thanks Kirk for extra hints.
    – jan_b
    Commented Nov 16, 2011 at 6:53

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.