Question : Another boring Lat/Long to X/Y question with bonus!

ZZzzzzz. Sorry, I nodded off there.

So, I've been snooping around EE and have read a lot about the conversion from geocode to cartesian. I'm still a little fuzzy on the whole deal and need to clarification before I plop some hard-earned cash down for a map.

Dig this, I am planning to buy a map. It is a Mercator projection of the United States. From the map maker, I will get the lat and longitude of the maps corners. Also, knowing that the image's width and height, I should be able to freely convert lat/long to x,y.

I found a nice little formula written in Actionscript, but I'm not savvy enough to verify if it's correct or not. From the description it sounds like it is, but I'm too skeptical to believe everything I find on the internet is 100% accurate. :)

http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/Q_23284979.html?sfQueryTermInfo=1+lat+long+x+y

Is this formula correct for a Mercator projection?

Also, what was that old TV commercial back in the 80s where you could write off for some kind of free brochure and at the end they always said, "Just write <something something> Pueblo, Colorado."

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
//MAP SIZE
var xwidth:Number = 2860;
var yheight:Number = 1900;
 
//MAP COORDINATES
var longN:Number = 76.7;  //Y1:0
var latW:Number = 74.0;   //X1:0
var longS:Number = 40.3;  //map helght Y2
var latE:Number = -44.6;  //map width   X2
 
//CONVERT MAP LONG, LAT TO X,Y COORDINATES
var x:Number;
var y:Number;
x = xwidth/(latE-latW);
y = yheight/(longN-longS);
trace("map x: " + x);
trace("map y: " + y);

Answer : Another boring Lat/Long to X/Y question with bonus!

No, that formula is not correct. I think the intent of that formula is to perform a linear interpolation, and if that is the case, the following is closer to what you want...

mapWidth = 2860;
mapHeight = 1900;

mapLongW = -125; // Left bound of map is 125degW
mapLongE = -65;    // Right bound of map is 65degW
mapLatN = 50;        // Top bound of map is 50degN
mapLatS = 25;        // Bottom bound of map is 25degN

locationLat = 30.52; // Latitude of point of interest
locationLong = -87.85; // Longitude of point of interest

x = (locationLong - mapLongW) * mapWidth / (mapLongE - mapLongW);
y = (locationLat - mapLatN) * mapHeight / (mapLatS - mapLatN);


HOWEVER, this is not an accurate method of converting lat/long to x/y. This is performing LINEAR interpolation, which is fine for the x value as the horizontal scale is linear but the vertical scale is not linear, so you will get the right values at the top and bottom of the map, but the close to the middle the bigger the error that you will get.

The error may be small enough for you to not be concerned about, but if you are the maths gets quite a bit more complicated. Have a you at the equations on this page....

http://en.wikipedia.org/wiki/Mercator_projection
Random Solutions  
 
programming4us programming4us