1

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.

Example

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.

2

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

2

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.

1

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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