12,404,478 members (71,690 online)
Rate this:
See more:
I have been searching for days on end to try and find a solution to this problem. I have a large set of latitude and longitude coordinates and I need to convert each latitude and longitude to a set of X and Y (and possible Z) coordinate to display on the screen.

I have one idea but I don't think that it is the best way to go.
Basically using this formula

```a = sin²(Δφ/2) + cos(φ1).cos(φ2).sin²(Δλ/2)
c = 2.atan2(√a, √(1−a))
d = R.c
```

d will be equal to the distance between the 2 points. So if i have a latitude of 73, I could find the distance from 0 To 73 and somehow scale that point to be visible on a 640,480 display. I could do the same with the longitude and get a set of 2 large numbers. (EG, 2254,7895). If those numbers were somehow scaled to fit on a 640,480 display I could get a coordinate of 60,48.

I don't think that this is the most (or even the right way) efficient way to do this.

Have any suggestions on a different approach to this problem?
Posted 26-Jul-13 2:25am

Rate this:

Solution 1

```x = R * cos(lat) * cos(lon)
y = R * cos(lat) * sin(lon)
z = R *sin(lat)```

Where R is the approximate radius of earth (e.g. 6371KM).

For back conversion it would be:
```lat = asin(z / R)
lon = atan2(y, x)
```

Can try some different methods:
http://stackoverflow.com/questions/6172355/how-to-convert-lat-long-to-an-xy-coordinate-system-e-g-utm-and-then-map-this[^]
http://stackoverflow.com/questions/2026112/how-do-i-convert-latitude-longitude-into-x-y-coordinates[^]
ExcelledProducts CEO 26-Jul-13 8:45am

when I use the formula to get the X coordinator i run into the same problem as before. I get a huge number (1449.9676155701172). I need to scale this number to the size of the display window of 640 x 480
Rate this:

Solution 4

I had deleted the solution because I thought it was not "professional", but seeing your comments to other questions... I am getting it back from the Limbo. This is the text:

Probably this is not going to be the best approach as well but... at least it could make it a bit easier. I am supposing that you don't need the Z-Axis

Your display is quite small (640,480) so the resolution is not going to be so accurated anyways.

If you consider the world as a 2d Map, the point of Latitude=0°0' and Longitude=0°0' is your X=0, Y=0, which is in the center of the display Pixel=(340,240)

So that 179° and 89' = the border of the screen.

You could apply:
-X (West) = 340 - (((Degree * Minute) * 340) / (179 * 89))
+X (East) = 340 + (((Degree * Minute) * 340) / (179 * 89))

+Y (North) = 240 - (((Degree * Minute) * 240) / (179 * 89))
-Y (South) = 240 + (((Degree * Minute) * 240) / (179 * 89))

Does it maybe help?

EDIT:
Since you mentioned that you want it in a sort of 3d cylinder then you can use the principle of solution 2 and apply part of my "thinking" to make the scales adapting it to your view-model.

EDIT_2:
Answer to comment 1 and 2:
If the coordinates are in decimals... it is even easier. I consider the format of your 2nd comment (Positive to north and east). Then the formulas will change to:
X=340 + ((Longitude*340)/180)--> X=340 + ((-72.7321095*340)/180)--> X=202.617--> X=203
Y=240 - ((Latitude*240)/180)--> Y=240 - ((41.6970505*240)/180)--> Y=184.403--> Y=184

Note:
Pay attention to the different signs. The minus (-) in Y is because North coordinates are positive, but you need to decrease the pixels to go upwards because the Pixel (0,0) is in the upper-left corner.

EDIT_3
In 640x480 Resolution of display, you are not going to have any difference considering the seconds or not. 360*2 = 720 and 720>640 so you are already not going to be able to accurately represent points in less than 35 or 40 Minutes scale.
If you want to do it anyways, the only thing you have to do is to add the seconds to the formula.
-X (West) = 340 - (((Degree * Minute * Second) * 340) / (179 * 89 * 89))
+X (East) = 340 + (((Degree * Minute * Second) * 340) / (179 * 89 * 89))

+Y (North) = 240 - (((Degree * Minute * Second) * 240) / (179 * 89 * 89))
-Y (South) = 240 + (((Degree * Minute * Second) * 240) / (179 * 89 * 89))

EDIT_4:
Corrected the 59' to 89'. I just read that the minutes and seconds are divided in 90 Units not in 60 as I was supposing.
v6
ExcelledProducts CEO 26-Jul-13 11:27am

this will work most likely but my latitude and longitudes are in decimals
Nelek 27-Jul-13 14:36pm

ExcelledProducts CEO 26-Jul-13 11:29am

lat="41.6970505" lon="-72.7321095"
Nelek 27-Jul-13 14:36pm

ExcelledProducts CEO 26-Jul-13 11:41am

also what if I have a Degree Minute Seconds format
Nelek 27-Jul-13 14:36pm

ridoy 26-Jul-13 12:22pm

good one i should say..+5 from me :)
Nelek 27-Jul-13 14:13pm

Thank you
ExcelledProducts CEO 27-Jul-13 18:24pm

it is working perfectly thank you very much :)
Nelek 28-Jul-13 17:30pm

Glad to help, you are welcome :)
Rate this:

Solution 2

What you are looking for is a so-called projection. And for mapping the surface of a sphere to a plane there are many alternatives, each of them having their specific advantages and disadvantages. Example are: Cylindrical, Conical, Conformal, ...

Take a look at http://en.wikipedia.org/wiki/Projection_%28cartography%29[^]

to get a feel for the basics. Then decide, which projection would be most suited for your application. To write the code for that projection is usually the easiest part and more or less straight forward.

[EDIT]
Ok, cylindrical is what you like. That is an easy one.

(a) Map your longitude to the x-coordinate by simple multiplication by a scale factor. Choose that factor in a suitable way such that the desired longitudinal range fits on your window.

(b) Now the latitude: At the equator, the latitude is mapped to the y-axis by the same factor as you used for the longitude. But with increasing latitude, parallels must be spread wider and wider in order to maintain angular correctness. So you have to apply tan (lat) and then multiply with the same scale factor as in x-direction.
v2
ExcelledProducts CEO 26-Jul-13 8:47am

I think Cylindrical is what I'm looking for but I see no equations on it?
nv3 26-Jul-13 9:22am

See the amendments after [EDIT].

Top Experts
Last 24hrsThis month
 OriginalGriff 253 Karthik Bangalore 225 Suvendu Shekhar Giri 205 ppolymorphe 200 Richard MacCutchan 122
 OriginalGriff 7,411 ppolymorphe 3,230 Karthik Bangalore 3,177 Richard MacCutchan 2,372 F-ES Sitecore 2,262