Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to get the position of a coordinate on this map (source Wikipedia): enter image description here

If I'm correct than the formula for the position of the latitude would be:

    R * ln(tan(pi/4 + latitude / 2))

But I can't get it to work. The map is 707 px wide so

    R = 707 / pi / 2

right? I tried filling in a latitude of 51° like this:

    707 / pi / 2 * ln(tan(pi / 4 + 51 / 2)) = 91

And if you go to 91 px above the equator then you're somewhere in Spain, which is too low. I was looking for the location of Belgium instead.

share|improve this question
7  
That last formula is strange in the way it mixes radians ("pi / 4") and degrees ("51 / 2"). If you actually did this calculation as written, this alone would explain why you're getting unexpected results! –  whuber Feb 22 '12 at 14:07
    
I've got the formula from mathworld.wolfram.com/MercatorProjection.html And that same formula is on en.wikipedia.org/wiki/Mercator_projection too. –  Jef Feb 22 '12 at 18:43
    
From the Wikipedia text preceding the formula: "... and φ and λ are given in radians." –  whuber Feb 22 '12 at 20:23
    
Oh man, I totally overlooked that. –  Jef Feb 22 '12 at 20:34
    
It's easy to do :-). (Who uses radians for lat, lon besides mathematicians?) Everybody gets bitten by that one once (and then remembers forever to be careful with trig formulas...). –  whuber Feb 22 '12 at 21:10
add comment

1 Answer 1

up vote 6 down vote accepted

The formula and its application are basically correct: the length of the Equator is 2 * pi * R and equating that with 707 pixels tells us the scale of the map at the Equator. However, any formula involving trigonometric functions of angles that involves pi expects the angles to be given in radians. Therefore, the Mercator position of latitude 51 degrees must be computed as

707 / (2 * pi) * ln(tan(pi / 4 Radians + 51 / 2 Degrees))
= 707 / (2 * pi) * ln(tan(pi / 4 + (51/2) * pi / 180))
= 707 / (2 * pi) * ln(tan(1.23046))
= 116.8

pixels above the Equator.

If degrees are treated as if they were radians, then pi/4 + 51/2 radians is the same as 42.0848 degrees (plus four whole circles--8*360--which makes no difference), which indeed places the location in Spain rather than Belgium. In this case it seems like a relatively small error of just 117 - 91 = 26 pixels has occurred, which can be misleading, because at other latitudes the result would be incredibly far off or undefined. For instance, using 52 instead of 51 in the formula gives a negative tangent whose logarithm is undefined. Increasing to 54.977871437821385 places you 3786 pixels below the Equator!

share|improve this answer
    
+1 whuber for reinforcing that the formulas must be expressed in radians. –  Stephen Quan Feb 22 '12 at 19:29
    
After rereading your answer, I like it better than mine :) –  Stephen Quan Feb 22 '12 at 21:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.