I have a point and a polyline. I need to find the perpendicular distance between each segment of the polyline and the point. By each segment of the polyline I mean that, each polyline may contain more than one line and I need to find every line of the polyline and find the perpendicular distance. I know its really easy using ICurve.QueryPointAndDistance Method. But to use this method, I need to create polylines from each segment of the actual polyline. But it is really time consuming for more than 13k polyline features.

So I tried to create line from every segment of the polyline. And calculate perpendicular distance from a point to the line. but this distance is not same as the distance I get from ICurve.QueryPointAndDistance Method's distanceFromCurve.

image is attached for better understanding

Question: Is there any better option to calculate perpendicular distance that will be same as the ICurve.QueryPointAndDistance Method's distanceFromCurve? Or what is the reason I am not getting the same result as ICurve.QueryPointAndDistance Method's distanceFromCurve?

I am using arcObjects and c#. the input feature layer is always projected. So I am getting X, Y value in meter/feet. For calculating perpendicular distance I am using following method:

private double GetPerpendicularDistance(Line line, Point point)
    var a = line.Point1.Y - line.Point2.Y;
    var b = line.Point2.X - line.Point1.X;
    var c = (line.Point1.X * line.Point2.Y) - (line.Point2.X * line.Point1.Y);

    var x = point.X;
    var y = point.Y;

    var d1 = Math.Abs((a * x) + (b * y) + c);
    var d2 = Math.Sqrt((a * a) + (b * b));
    var d = d1 / d2;
    return d;

Line is an internal class.

internal class Line
    internal Point Point1 { set; get; }
    internal Point Point2 { set; get; }

Point is another internal class.

internal class Point 
    internal double X { set; get; }
    internal double Y { set; get; }
  • 3
    Neither your illustration nor your code compute anything that would normally be interpreted as an "orthogonal distance": the illustration looks arbitrary (and has no evident relationship to the text or the code) while the code appears to compute the Euclidean distance between a point point and the line (not line segment!) determined by the endpoints of the line argument. Please explain what you really want to calculate and what kind of coordinate system is used to represent your data. – whuber Oct 27 '13 at 15:44
  • @whuber I agree with all that you say (except maybe what you say about the code). Ignoring the text and diagram (which are confusing), function GetOrthogonalDistance(L,P) does return the shortest distance from point P to the extension of segment L. Maybe that is what you're saying, though :-) – Martin F Oct 28 '13 at 5:23
  • 1
    @martinf: 1. Yes, you are right. By "to use this method I need to create polylines from each part of the actual polyline." I mean that "to use this method I need to create segments from each part of the actual polyline." 2. By actual distance I mean that, the value I am getting from using ICurve.QueryPointAndDistance Method's distFrom. 3. My method is not faster than ICurve.QueryPointAndDistance Method. They are approximately same. But to use ICurve.QueryPointAndDistance, I need to extract all segments of the polyline and convert each segment to another polyline.This conversion takes time. – Emi Oct 28 '13 at 5:48
  • 1
    I have edited the question to make it better. Can you now have a look at it and help me to find any substitute? – Emi Oct 28 '13 at 7:37
  • 1
    +1 For the edits; the question is clear now. I doubt, however, that any GIS has this operation built in: something like your solution (which loops over all the segments of each polyline) is going to be needed no matter what. But it's fast code (it doesn't actually need to create line segments, it only computes distances): have you actually benchmarked it? – whuber Oct 28 '13 at 13:04

Your Answer

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

Browse other questions tagged or ask your own question.