I have a polyline and a point on the polyline. I need to find the distance from the from point of the polyline to that point.

enter image description here

ICurve.QueryPoint method does the opposite thing. It gives a point based on given distance. In ICurve.QueryPointAndDistance method, specified point is a outside point and it gives shortest distance. I could not find any method that gives the distance I require. So I have tried something different. I took the polyline and split at specific point using IPolycurve.SplitAtPoint Method. I wanted to get my desired part's length from splitted part. But I guess it was a wrong procedure. I found a geometry collection and those geometry were not type of esriGeometryPolyline, they were type of esriGeometryPath. And the length of the path is not similar of my desired part's length. Can anybody give me some pointer about how to get the length?


Actually ICurve.QueryPointAndDistance method gives the distance along the polyline in DistanceAlongCurve variable.

double GetDistanceAt(IPoint toPoint, IPolyline polyline)
    var outPnt = new PointClass() as IPoint;
    double distAlong = double.NaN;
    double distFrom = double.NaN;
    bool bRight = false;
    polyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, toPoint, false, outPnt, ref distAlong, ref distFrom, ref bRight);

    return distAlong;

Assuming the two points are on the the curve, you can use the QueryPointAndDistance on both points, get the difference and that is what you looking for.enter image description here

 Public Function distancebetweenTwoPoints(pPolyline As IPolyline, pPoint1 As IPoint, pPoint2 As IPoint) As Double


        Dim distancetoPoint1 As Double = 0
        Dim distancetoPoint2 As Double = 0
        'get the distance along curve for the first point 
        pPolyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pPoint1, False, Nothing, distancetoPoint1, 0, False)
        'get the distance along curve for the second point 
        pPolyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pPoint2, False, Nothing, distancetoPoint2, 0, False)
        'take the difference
        Return (Math.Abs(distancetoPoint2 - distancetoPoint1)) 'absolute that just in case point 1 is further to point 2 

    Catch ex As Exception
    End Try
End Function

More arcobjects stuff in my youtube channel here

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.