Tile Server - Coordinate Transformation

A tile server is a particular service that allow user to retrieve preprocessed map data. It can be done using a particular protocol for retrieve data:

  • TMS if map tiles are stored locally
  • WTMS if map tiles are stored on a server

Normally the choosen protocol divide the large image in many sub image, that is named pyramidal subdivision, in that case we have many zoom level (2n*2n) and a lot of tile that need to be processed.

Every tile must be placed in the right position of a cartographic projection, e.g. Mercator, with a geodetic system note, e.g. WGS84, that can be achieved by a transformation of latitude and longitude in cartesian coordinate.

Here is the mathematical formula for coordinate translation

Here are the pseudo code for:

  • Getting lat/lon coordinates from specific tile


n = 2 ^ zoom
deg_longitude = xtile / n * 360.0 - 180.0
rad_latitude = arctan(sinh(π * (1 - 2 * ytile / n)))
deg_latitude = rad_latitude * 180.0 / π


  • Getting x,y tiles coordinate from know lat/lon coordinates


n = 2 ^ zoom
xtile = n * ((deg_longitude + 180) / 360)
ytile = n * (1 - (log(tan(rad_latitude) + sec(rad_latitude)) / π)) / 2