Select to view content in your preferred language

Polyline - Nearest point

5048
7
06-21-2011 10:41 AM
PaulHedlund
New Contributor II
How do I find the location on a polyline that is closest to another point on the map.  For a visual of what I am looking for, in the attached PolylinePoint.png I want to obtain the yellow "Nearest Point' location.

The geometry task 'DistanceAsync' gets the closest distance between a polyline and point.  However, I am looking for that 'Nearest Point' location.
0 Kudos
7 Replies
wangzhifang
Occasional Contributor
This can be done easily by client side.
Just use dist=Math.Square(a*a+b*b) to calculate every distance between your point and each point on the polyline, then you get the nearest point on the polyline.
0 Kudos
PaulHedlund
New Contributor II
The problem is I am looking for the nearest location on the polyline.  The location may not contain a vertex. (see attached visual)

Looping through each vertice and using your forumla would give me the distance from each vertice.  But, that is not what I am looking for.

The 'DistanceAsync' task gives me the distance, but for some reason I can't get the polyline nearest location.  I would think the value for this would be exposed somewhere.
0 Kudos
Sravan_KumarUddarraju
New Contributor
I am looking for the samething. I need to find nearest point on the segment.
Were you able to find the solution for this?

Srav
0 Kudos
SimoLukic
New Contributor
Maybe convert the polyline into a List of Points.
If you have a line  between x1 and x5, cut it in pieces and check for distence with x2,x3,x4.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
If the segment is a straight line (i.e. not an arc, ellipse, ...), it looks easy:
    - project the point on the line,
    - if the projected point is on the segment => it's the shortest distance
    - if not on the segment, thye shortest distance is given by the closest vertex.
0 Kudos
CostasKotzabassis
New Contributor
Hello Dominique,
I found your response intriguing, but I cannot quite follow.
How do you project a point to a line segment using Silverlight API 3.1?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Hello Dominique,
I found your response intriguing, but I cannot quite follow.
How do you project a point to a line segment using Silverlight API 3.1?


I put together a Geometry Projection sample.
0 Kudos