I have 2 lines Line A, and Line B that share from point. The 2 lines at first share the same path and are parallel, then they split into different paths. I would like to calculate that segment in which they are parallel. Picture below further explains visually. Red part is the wanted part.


Note that the red segment might be multiple connected segments that make up the red path of each Polyline. I doubt there is an interface in the arcobjects in which calculates this, which means I have to calculate it manually. I need some suggestions to get the best accurate result of the shared length.


Using the ITopologicalOperator interface, I can create a buffer for both line features, and then using the Intersects method which will return a geometry of the result of the intersection, which is the parallel section of the line. Then I can get it's length


I would access ITopologyExtension.MapTopology, call IMapTopology.AddClass to add your featureclass with a cluster tolerance a bit larger than the distance between the parallel lines.

Call ITopologyGraph.Build, then loop through each topology edge via ITopologyGraph.Edges, to populate a List<IGeometry> with geometries from ITopologyEdge.Geometry for edges where ITopologyEdge.Parents yields more than one parent.

I've also used a custom layer extension using ILayerExtensionDraw so that it simply draws the geometries (in red) for topology edges with more than one parent.


Using ITopologicalOperator on the geometries themselves can return the desired geometry. For instance the Intersect method has the option to choose the output geometry type. Since you are interested in the polyline result, you can choose esriGeometryDimension.esriGeometry1Dimension. For instance:

IGeometry geom1 = (IGeometry)line1;
IGeometry geom2 = (IGeometry)line2;
ITopologicalOperator topOp = (ITopologicalOperator)geom1;

IGeometry results = topOp.Intersect(geom2, esriGeometryDimension.esriGeometry1Dimension);

If the resulting geometry contains multiple geometries, you can cast the result to IGeometryCollection, and iterate through the parts.

IGeometryCollection geomColl = (IGeometryCollection)results;
if (geomColl.GeometryCount > 0)
    for (int idx = 0; i < geomColl.GeometryCount; i++)
        IPolyline resultLine = (IPolyline)geomColl.Geometry[idx];

        // do something with each resultLine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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