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.

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?

Any help or sample code would be appreciated.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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

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.