I'm trying to convert a latitude and longitude to an x and y point on
a map. The map in question is a Mercator projection (see
http://en.wikipedia.org/wiki/Mercator_projection). Longitude(x) is
very easy but I'm having trouble programmatically calculating
latitude(y), since it's obviously not linear.
I have various maps that I can use (different sizes and layouts) but
all are the same projection (Mercatur) and in each case, I know the
pixel offset of 0,0. For example, suppose a given map was 800 pixels
wide and 500 pixels high and was perfectly centered, I know that at
pixel 400x250 is latitude 0 longitude 0. I know the top of the map is
at row 0 (latitude 86.0000 or thereabouts, since the 90 degree point
is infinite), so assuming mercator projection I'd like to calculate
the Y point (0-500, with 250
being a latitude of 0) given a certain latitude. I obviously know a
latitude of 45.0000 is between pixel 0 and 250, but can't seem to
calculate the correct pixel using the formula on the wikipedia entry.
Programmatically I'm using .NET (C#, but any .NET language is good) so
an answer that includes an example in .NET is ideal. |
Clarification of Question by
tommy2005-ga
on
15 Dec 2005 13:34 PST
Clarification:
I can calculate the scale based on the formula:
z = ln(tan(latitude/2 + pi/4))
where latitude is the latitude in radians.
The challenge is applying that value correctly given an arbitrary map
height n. I do know, though, where latitude 0 and, say, latitude 60
is on the map, so can calculate the pixel difference between them.
|