Converting Web Mercator projection to equirectangular

Written by Paul Bourke
May 2021


So called "Web Mercator" map projections are a variation on the standard Mercator projection that was strangely chosen as the standard for Google Maps, chosen presumably due to slightly simpler computation. It is also sometimes known as the "Pseudo Mercator" and is one of a family of cylindrical projections. The main variation from the Mercator is that points are projected onto a sphere of radius 6378137m instead of an ellipsoid. This means that it no longer preserves scale in all directions and is therefore no longer conformal.

The following presents the equations one needs in order to map such a Web Mercator projection to the equirectangular projection, for example, so that it can be used as a texture on a standard UV texture mapped sphere.

The equations are given below where (u,v) are the usual texture coordinates each ranging from 0 to 1. The most commonly used maximum latitude is the one that leads to a square image, namely a little over 85 degrees.

The limited maximum latitude means the final equirectangular image is undefined between 85 and 90 degrees latitude, and -90 to -85 degrees latitude.

A sample Web Mercator projection.

Corresponding equirectangular projection.

A simple image conversion command line utility was written to do the conversion. It performs a simple supersampling anti-aliasing, the degree dictated by the -a command line option. The input Web Mercator image is assumed to be square and the created equirectangular will have the expected 2:1 aspect ratio. The undefined 5 degrees at the north and south pole will be set to the background colour. The usage string is as follows.

Usage: webmerc2sphere [options] imagefile
Options
   -w n        sets the output image size, default: 2 x input width
   -a n        sets antialiasing level, default: 2
   -bg r g b   set background colour, default: grey or black for blending
   -d          debug mode

References

  • "WGS 84 and the Web Mercator Projection NGA Office of Geomatics" (PDF). National Geospatial Intelligence Agency. 2014-05-16

  • Snyder, J. P. (1987). Map Projections: A Working Manual. U.S. Geological Survey Professional Paper 1395. Washington, DC: United States Government Printing Office.

  • Strebe, Daniel "daan" (2019). "A bevy of area-preserving transforms for map projection designers". Cartography and Geographic Information Science. 46 (3). doi:10.1080/15230406.2018.1452632.

  • Snyder, J. P. and Voxland, P. M. (1989). An Album of Map Projections. U.S. Geological Survey Professional Paper 1453. Washington, DC: United States Government Printing Office.

  • Battersby, S., Finn, M. P., Usery, E. L. and Yamamoto, K. (2014). "Implications of Web Mercator and Its Use in Online Mapping." Cartographica, The International Journal for Geographic Information and Geovisualization, 49 (2), p. 85-101. DOI: 10.3138/carto.49.2.2313