Lattitude and Longitude to X,Y

  • Thread starter Thread starter k_squared
  • Start date Start date
  • Tags Tags
    Longitude
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
10 replies · 10K views
k_squared
Messages
62
Reaction score
0
I was writing a program to place a markers on a map of the United States, for a Civil War battlemap generator. I tried this:

Assuming x,y and lat/long are superimposed yet different coordinate systems. For example, if a coordinate system with a unary equivalent to 12 on the other were to exist, express two concurrent points. Then use the distance formula:
sqrt( (24+12)^2+(24+12)^2)/sqrt ( (2+1)^2+(2+1)) = 12 (as do all other concurrent values.)

I found pixel where the four corners states meet (195,306), and a point in Florida. Using the formula above, with lat/long and x/y I calculated a conversion factor of about 14. However, when I did the four corners and the Lake Michigan. The conversion factors varied dramitcally. I thusly assume the the lines curve, even on a flat projection where Texas looks like its near Florida? My code went thus...
Code:
const float refcoord[2]={36.998976, -109.045172};
const float conversionfactor=0.17975951;
const int refpix[2]={195,306};
void drawID(float lat, float lon, FXint& x,FXint& y){
x=refpix[0]-(refcoord[0]-lat)/conversionfactor;
y=refpix[1]-(refcoord[1]-lon)/conversionfactor;
}

If this is the problem I think it is, could someone link me to some trig help? Thanks a lot.
 
Physics news on Phys.org
The size of a degree of longtitude (x-axis) depends on your latitude (since the Earth gets smaller nearer the poles)
The size of a degree of longitude is the same everywhere.

So you need a different scaling factor in X and Y
 
What is the sequence or function that would define this scaling factor for x? I figured out the ratio above on my own, but my math education at the moment, is limited (trig). Or how would I determine it?

Thanks again.
 
Last edited:
Try googling "longitude x latitude y".
 
Whenever I put in that calculation for (3.141592654/180)*Cos(0)*6367449 I get 111132.950017331. This must be wrong (by several factors of 10). Also, I get 0.0174.. whenever I do the more complex equation (with the polar and equatorial radii) with Cos(0). Cos(0) is, of course, 1.

In fact I seem to be encountering .017 type stuff a LOT. Is that a constant... or something near a standard cos(x)?

Thanks again...
 
There are about 111km/deg at the equator so that's probbaly the value for longtitude in metres.
0.0174 sounds a lot like 1deg in radians - remember you computer/calcualtor is workign in radians
 
Ahhhhhhhhhhhhhhhhhhhhhhhhh... should've seen THAT coming.

Thanks.
 
Because I am a glutton for pain, I have decided to carry this one through (if I can). Aside from the obvious (km means 1000) and the less than obvious (cos(x)*6...). I tried to develop a new conversion ration JUST going vertical (different Y on a fixed X)... but the inaccuracy is .08 every 10 degrees (ratio/ratio, basically.) Is a fixed conversion ratio for longitude even valid? Otherwise, would this piece of code do it?

Code:
const float refcoord[2]={36.999, -109.05};
const float conversionfactor=4.3; ///The AVERAGE conversion ratio
const int refpix[2]={321,337};
void drawID(float lat, float lon, FXint& x,FXint& y){
x=refpix[0]-(refcoord[0]-lat)*(conversionfactor*((float(180/3.141)*cos(float(3.141/180)*lat)) ));
y=refpix[1]-(refcoord[1]-lon)*conversionfactor*-1;
}

It gets practice, it gets fairly close (within the size of my marker) for some locations (St. Louis). However, there is a magic threshold somewhere my X value becomes fairly massive (lake Michigan). (If anyone wants this threshold, I can figure it out by just systematically logging the output of the sub.)

Oh... and thanks for the help.
 
mgb_phys said:
The size of a degree of longtitude (x-axis) depends on your latitude (since the Earth gets smaller nearer the poles)
The size of a degree of latitude is the same everywhere.

So you need a different scaling factor in X and Y

Corrected...

Most navigational charts are http://en.wikipedia.org/wiki/Lambert_Conformal_Projection" , which have two parallel lines of latitude secant to the globe and intersecting it. The result is a chart of least distortion for it's scale, and where straight lines drawn on the chart closely approximate great circle lines.

If you're starting with an LCC, you can use http://en.wikipedia.org/wiki/Lambert_Conformal_Projection#Transformation"to convert spheric coordinates into the projection coordinates. This is useful, as this is what most electronic mapping software uses to pinpoint one's location on a digitized chart from GPS feeds.

k_squared said:
Because I am a glutton for pain...

Oh... and thanks for the help.

No worries! http://fer3.com/arc/img/106859.pre-comp%20pages%20from%20afpam11-216.pdf" (but it's the good kind). Be forewarned, however, as it's a 70 MB file.

Check out page 395. I think you may find it helpful. :smile:
 
Last edited by a moderator: