[OSM-dev] tile calculation

Claudomiro Nascimento Jr. claudomiro at gmail.com
Sun Jul 29 22:34:39 BST 2007


This is my (verbose) translation in Java:

    private static final double MIN_LAT = -85.0511;
    private static final double MAX_LAT =  85.0511;
    private static final double MAX_Y   = toY(MAX_LAT);
    private static final double MIN_Y   = toY(MIN_LAT);
    private static final double RANGE_Y = MAX_Y - MIN_Y;

    public static short getY(int z, double lat) {
        return (short) Math.floor(((MAX_Y - toY(lat)) / RANGE_Y) *
worldSize(z));
    }

    public static short getX(int z, double lon) {
        return (short) Math.floor(((lon + 180) / 360) * worldSize(z));
    }

    public static double toY(double lat) {
        double latRad = toRads(lat);
        return Math.log(Math.tan(PI/4 + latRad/2));
    }

    private static int worldSize(int z) {
        return 1 << z;
    }



2007/7/29, Rob Aerts <rob at coolbegin.com>:
>
> i try to calculate the x and y tile url in c
>
> the example on the wiki (in perl code) looks like
> my $xtile = int( ($lon+180)/360 *2**$z ) ;
> my $ytile = int( (1 - log(tan($lat*pi/180) + sec($lat*pi/180))/pi)/2
> *2**$z ) ;
>
> i can't figure out the sec formula in the $ytile
>
> wiki : http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames
> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20070729/c2fbd0e8/attachment.html>


More information about the dev mailing list