views:

418

answers:

1

Hi

I have this image: http://imgur.com/99tSz.png. A map of the UK (not including Southern Ireland).

I have successfully managed to get a latitude and longitude and plot it onto this map by taking the leftmost longitude and rightmost longitude of the UK and using them to work out where to put the point on the map.

This is the code (for use in Processing.js but could be used as js or anything):

// Size of the map
int width = 538;
int height = 811;
// X and Y boundaries
float westLong = -8.166667;
float eastLong = 1.762833;
float northLat = 58.666667;
float southLat = 49.95;

void drawPoint(float latitude, float longitude){

 fill(#000000);

 x = width * ((westLong-longitude)/(westLong-eastLong));
 y = (height * ((northLat-latitude)/(northLat-southLat)));

 console.log(x + ", " + y);
 ellipseMode(RADIUS);
 ellipse(x, y, 2, 2);    

}

However, I haven't been able to implement a Mercator projection on these values. The plots are reasonably accurate but they are not good enough and this projection would solve it.

I can't figure out how to do it. All the examples I find are explaining how to do it for the whole world. This is a good resource of examples explaining how to implement the projection but I haven't been able to get it to work.

Another resource is the Extreme points of the United Kingdom where I got the latitude and longitude values of the bounding box around the UK. They are also here:

northLat = 58.666667; 
northLong = -3.366667; 
eastLat = 52.481167; 
eastLong = 1.762833; 
southLat = 49.95;
southLong = -5.2; 
westLat = 54.45;
westLong = -8.166667;

If anyone could help me with this, I would greatly appreciate it!

Thanks

+1  A: 

I think it's worthwhile to keep in mind that not all flat maps are Mercator projections. Without knowing more about that map in particular, it's hard to be sure. You may find that most maps of a small area of the world are more likely to be a conical type projection, where the area of interest on the map is "flatter" than would be on a global Mercator projection. This is especially more important the further you get away from the equator (and the UK is far enough away for it to matter).

You may be able to get "close enough" using the calculations you're trying, but for best accuracy you may want to either use a map with a well-defined projection, or create your own map.

Greg Hewgill
I'm fairly certain it is - on this page: http://en.wikipedia.org/wiki/Mercator_projection#Uses it mentions Google Maps uses the projection. I overlayed the map included in my post (also found here: http://en.wikipedia.org/wiki/File:Uk-map.svg) onto a Google map version and they fitted exactly so that made me think that it was. Is it still possible to use the Mercator projections? If not only to see if that solves the problem.. Or should I rethink my maps?
betamax
@betamax: Well, it looks like that map may indeed be Mercator. It's certainly possible to project lat/lon onto an existing map, and in fact your linear interpolation method should work just fine for the longitude. For the latitude, however, you will need to use the projection equations presented on that wikipedia page, and work out the relationship between the actual latitude and the coordinates on your map. It should be a linear relationship (meaning only a multiply and an add) between the Mercator `y` and your map coordinate `y'`. That is, y' = Ay + B for some A and B.
Greg Hewgill