tags:

views:

47

answers:

3

Hi,

I have a map with locations as shown in the image below.

alt text

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

+1  A: 

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.

davisoa
I was already using this formula to calculate straight line distance - but out of everything I tried it never occurred to me to pick a point on the south west corner and sort from there!
markpirvine
A: 

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.

stevemegson
Hi, I'm not really following what you've said. When I sort on x+y, it will give the green '3' marker near Enniskillen. However if I remove this, I'd expect to get the green '4' marker near Enniskillen. I actually get the green '1' marker near Coleraine at the top of the map. Could you provide some pseudo code?
markpirvine
A: 

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/

Malevolence
Thanks for the link - sample code is great!
markpirvine