[OSM-dev] Good explanation of latitude-to-pixel conversion?

OJ W ojwlists at googlemail.com
Sat May 17 14:37:59 BST 2008


Copy the explanation into:

http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames

if you find a good description...


e.g. wikipedia will tell you all about how mercator itself works:

http://en.wikipedia.org/wiki/Mercator_projection

and for the tiles, alll you do is say "select the bit of
mercator-projected map between two arbitrary latitudes (which happen
to be numerically special but you don't need to care about that) and
call that range the limits of your map in Y.

you then just start dividing Y into halves and quarters etc. to do the tiles.




On Sat, May 17, 2008 at 2:29 PM, Nick Whitelegg
<Nick.Whitelegg at solent.ac.uk> wrote:
> Am in the process of developing a mobile client for Freemap, and
> potentially (in conjunction with one of my students) a tool for OSM as a
> whole. Part of this involves converting lat/lon to "Google" Mercator pixel
> coordinates.
>
> I have the code to do this, but I guess I'm one of these people that like
> to understand what's actually going on :-) Am happy with the lon->y
> conversion but would like some clarification on the lat->x conversion; all
> the articles I've found so far basically just give you the formula and say
> "here, use it". Does anyone know of any good references which fully
> explain the maths behind it?
>
> The specific formula I mean (represented in Java) is:
>
> public static int latToY(double lat,int zoom)
> {
>                double f = Math.sin((Math.PI/180)*lat);
>
>                int y = (int)Math.round
>                        (Math.pow(2,zoom+7) + 0.5*Math.log((1+f)/(1-f)) *
> (-Math.pow(2,zoom+8)/(2*Math.PI)));
>                return y;
> }
>
> Thanks,
> Nick
>
> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev
>




More information about the dev mailing list