Skip to content

Instantly share code, notes, and snippets.

@tmcw
Last active February 11, 2026 06:42
Show Gist options
  • Select an option

  • Save tmcw/4954720 to your computer and use it in GitHub Desktop.

Select an option

Save tmcw/4954720 to your computer and use it in GitHub Desktop.

Revisions

  1. tmcw revised this gist Feb 15, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion xyz_vs_tms.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ ending in `/0/0/0.png` or something. Sometimes if it's a script, it'll look like

    Good examples are OpenStreetMap, Google Maps, MapBox, MapQuest, etc. Lots of maps.

    Most of those are in XYZ. The best documentation for that is [slippy map tilenames](http://wiki.openstreetmap.org/wiki/slippy_map_tilenames) on the OSM Wiki.
    Most of those are in XYZ. The best documentation for that is [slippy map tilenames](http://wiki.openstreetmap.org/wiki/slippy_map_tilenames) on the OSM Wiki, and Klokan's [Tiles a la Google](http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/).

    Some of them are in TMS instead. TMS is an OSGeo spec. [Here's the wiki page on it](http://en.wikipedia.org/wiki/Tile_Map_Service). It's less popular and few services support the whole spec.

  2. tmcw revised this gist Feb 15, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions xyz_vs_tms.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ Let's get to the point. The only difference between the two is a flipped y coord

    In math:

    y = (2^z) - y - 1;
    y = (2^z) - y - 1

    javascript

    @@ -35,13 +35,13 @@ y = pow(2, z) - y - 1;
    python

    ```php
    y = (2 ** z) - y - 1;
    y = (2 ** z) - y - 1
    ```

    ruby

    ```ruby
    y = (2 ** z) - y - 1;
    y = (2 ** z) - y - 1
    ```

    ### Addendum
  3. tmcw revised this gist Feb 14, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion xyz_vs_tms.md
    Original file line number Diff line number Diff line change
    @@ -46,4 +46,6 @@ y = (2 ** z) - y - 1;

    ### Addendum

    When I say 'no difference' or 'no advantage' I mean for most maps. If you have some weird projection, use TMS but ideally don't make a tiled map in a weird projection in the first place. If you're forced to use OSGeo standards, do that but try to find a different job.
    When I say 'no difference' or 'no advantage' I mean for most maps. If you have some weird projection, use TMS but ideally don't make a tiled map in a weird projection in the first place. If you're forced to use OSGeo standards, do that but try to find a different job.

    This originally credited OGC with TMS. It was OSGeo. OGC has WMTS. Don't use that either.
  4. tmcw revised this gist Feb 14, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions xyz_vs_tms.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ Good examples are OpenStreetMap, Google Maps, MapBox, MapQuest, etc. Lots of map

    Most of those are in XYZ. The best documentation for that is [slippy map tilenames](http://wiki.openstreetmap.org/wiki/slippy_map_tilenames) on the OSM Wiki.

    Some of them are in TMS instead. TMS is an OGC spec. [Here's the wiki page on it](http://en.wikipedia.org/wiki/Tile_Map_Service). It's less popular and few services support the whole spec.
    Some of them are in TMS instead. TMS is an OSGeo spec. [Here's the wiki page on it](http://en.wikipedia.org/wiki/Tile_Map_Service). It's less popular and few services support the whole spec.

    There are no advantages of XYZ over TMS or vice-versa for most maps*, but XYZ is more popular.

    @@ -46,4 +46,4 @@ y = (2 ** z) - y - 1;

    ### Addendum

    When I say 'no difference' or 'no advantage' I mean for most maps. If you have some weird projection, use TMS but ideally don't make a tiled map in a weird projection in the first place. If you're forced to use OGC standards, do that but try to find a different job.
    When I say 'no difference' or 'no advantage' I mean for most maps. If you have some weird projection, use TMS but ideally don't make a tiled map in a weird projection in the first place. If you're forced to use OSGeo standards, do that but try to find a different job.
  5. tmcw created this gist Feb 14, 2013.
    49 changes: 49 additions & 0 deletions xyz_vs_tms.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    The difference between XYZ and TMS tiles and how to convert between them

    Lots of tile-based maps use either the XYZ or TMS scheme. These are the maps that have tiles
    ending in `/0/0/0.png` or something. Sometimes if it's a script, it'll look like
    `&z=0&y=0&x=0` instead. Anyway, these are usually maps in Spherical Mercator.

    Good examples are OpenStreetMap, Google Maps, MapBox, MapQuest, etc. Lots of maps.

    Most of those are in XYZ. The best documentation for that is [slippy map tilenames](http://wiki.openstreetmap.org/wiki/slippy_map_tilenames) on the OSM Wiki.

    Some of them are in TMS instead. TMS is an OGC spec. [Here's the wiki page on it](http://en.wikipedia.org/wiki/Tile_Map_Service). It's less popular and few services support the whole spec.

    There are no advantages of XYZ over TMS or vice-versa for most maps*, but XYZ is more popular.

    ## Converting

    Let's get to the point. The only difference between the two is a flipped y coordinate.

    In math:

    y = (2^z) - y - 1;

    javascript

    ```javascript
    y = Math.pow(2, z) - y - 1;
    ```

    php

    ```php
    y = pow(2, z) - y - 1;
    ```

    python

    ```php
    y = (2 ** z) - y - 1;
    ```

    ruby

    ```ruby
    y = (2 ** z) - y - 1;
    ```

    ### Addendum

    When I say 'no difference' or 'no advantage' I mean for most maps. If you have some weird projection, use TMS but ideally don't make a tiled map in a weird projection in the first place. If you're forced to use OGC standards, do that but try to find a different job.