Converting latitude and longitude to x,y in a world map with mercator projection

I've bought this map:

http://www.mapresources.com/preview.asp?image=MC-EUR-091265&bs=eng&bo=0001&imagex=2&name=Mercator%20Europe%20Centered%20World

And now I need the way to plot the points correctly over it.

What I need from you GIS & GPS experts, is a function that gets lat and lon and returns x and y.

As a series of values is going to come from a MySQL database, be processed, and then passed by XML to a Flash web object, I need that function working in a scripting language that I can run on my Linux server. PHP, Perl... in an extreme case I consider installing something additional if you give me a solution that needs that, as I'm root at the machine. I Hope that won't be the only solution though :)

Thanks!
rockseltaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
You can find the formulas for the translation here
http://mathworld.wolfram.com/MercatorProjection.html
rockseltaAuthor Commented:
OK; I tried to overlay the red one in your URL with mine, in photoshop, and it overlayed perfectly, although I had to stretch it, the proportions didn't coincide. But how do I pass the width and height of the map to the formula? Thx
ozoCommented:
You'll want to determine the latitiude and longitude of the edges of the map (or some other points on the map with known x and y) in order to find the scaling factors.
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

rockseltaAuthor Commented:
You'll have to explain it as if I were a 5 year old otherwise I'm not going anywhere... been struggling with this long before buying a premium account here on EE, now I really need expert help, so please give me a more detailed solution... with examples probably. Thanks :)
ozoCommented:
Ok, I have to leave now, but I'll try to give a more detailed solution when I get back.
ozoCommented:
#!/usr/bin/perl
use strict;
use warnings;
use constant pi => 4*atan2(1,1);
sub mercatory{
    my $s = sin $_[0]*pi/180;
    return log((1+$s)/(1-$s))/2;
}
sub mercatorxy{
    my($lon,$lat,$minx,$maxx,$miny,$maxy,$minlon,$maxlon,$minlat,$maxlat) = @_;
    my $x = $minx+($lon-$minlon)*($maxx-$minx)/($maxlon-$minlon);
    $minlat = mercatory($minlat);
    $maxlat = mercatory($maxlat);
    $lat = mercatory($lat);
    my $y = $miny+($lat-$minlat)*($maxy-$miny)/($maxlat-$minlat);
    return ($x,$y);
}
#if longitudes from 180 to -180 correspond to x from 0 to 800
#and latitudes from -80 to +80 correspond to y from 0 to 600
#then longitude -10, latitude 40 would correspond to
print join(", ",mercatorxy(-10,40, 0,800, 0,600, 180,-180, -80,+80)),"\n";

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maphewCommented:
if ozo's script doesn't work well enough, the proj4 library, http://proj.maptools.org/, might do what you need.   Specificly the cs2cs program, something like this (in interactive mode):

  cs2cs +proj=latlong +to +proj=merc -r [Enter]
   45d15'33.1"    111.5W
   45d15.551666667N       -111d30
   +45.25919444444        111d30'000w
   [Ctrl-C]

all three coordinate pairs shown are the same place, just different ways of writing them.

the -r is to write Lat before Long (cs2cs expects longitude before latitude by default)

Note there a several mercator projections. You''ll might need to know exactly which one to get accurate results. List of proj4 keywords for projections are here: http://www.remotesensing.org/geotiff/proj_list/

However since you're building a web map, maybe something like Mapserver is more to your need.  http://mapserver.gis.umn.edu/
Hobu's "kitchen sink" package includes Flash output http://hobu.stat.iastate.edu/mapserver/
maphewCommented:
no objection.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
GIS/GPS Programming

From novice to tech pro — start learning today.