Converting Web Mercator projection to equirectangularWritten by Paul Bourke
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