How to detect a nearest co-ordinate from an array of co-ordinates ?

How to detect a nearest co-ordinate from an array of co-ordinates ?

Anonymous
Not applicable
435 Views
1 Reply
Message 1 of 2

How to detect a nearest co-ordinate from an array of co-ordinates ?

Anonymous
Not applicable

Hi all,

 

I have an array of co-ordinates (List A) from a polyline. I have one of the co-ordinate (B) from a polyline which is located around the array of co-ordinates of the other polyline (List  A).

 

I want to detect the co-ordinate in List A which is closest to co-ordinate (B).

 

Known co-ordinates would be, 

1. Array of co-ordinates

2. the reference co-ordinate.

Can anyone help ?

 

 

0 Likes
Accepted solutions (1)
436 Views
1 Reply
Reply (1)
Message 2 of 2

alberto_manero_geograma
Enthusiast
Enthusiast
Accepted solution

If what wou need is to get the nearest vertex, you could loop through all vertex and get the lowest value of:

 

        Math.Pow(vertex.X - coordinate.X, 2) + Math.Pow(vertex.Y - coordinate.Y, 2)

 

The lowest value indicates the nearest vertex.

 

 

 

But if you need the nearest point to the polyline, you could use the "GetClosestPointTo" method of the polyline.

Luis Alberto Manero, Geograma.com