Reputation: 1592
I have a map with locations as shown in the image below.
These locations are held in a C# Dictionary object with both Latitude/Longitude and Cartesian (x, y, z) coordinates. The area is covered by 5 teams, the first of which is in the south west of the area. What I need is to be able to order the points so that the most south westerly point is first - this would be the green '3' marker near Enniskillen on the map. I've been trying different approaches but not getting the result I want.
Can anyone explain an approach that would work?
Mark
Upvotes: 0
Views: 864
Reputation: 1857
I would use the Haversine formula to determine the distance between some location in the southwest corner of the map and each of the points. Here's a link with some code for both C# and Sql Server to do that very thing.
http://www.storm-consultancy.com/blog/development/code-snippets/the-haversine-formula-in-c-and-sql/
Upvotes: 0
Reputation: 12093
If you want to define "most south westerly" in a way similar to "most southerly", you could order the points (x,y)
by x+y
. You can think of this as moving a NW-SE line across the map from the SW corner, noting the order that the points are reached. This is equivalent to defining "most southerly" by sorting on y
, where you're moving an east-west line up from the south edge and noting the order that you reach each point.
Upvotes: 0
Reputation: 5439
Assuming you know the Lat / Long of the South West corner of this map, I would calculate the distance of each point from that corner using the Aviation Formulary. Then you just have to sort based on the distance calculated.
Upvotes: 1