block by oliverheilig 29e494c33ef58c6d5839

In Defense of Mercator

Full Screen

Note: I’m well aware that i am using “Web Mercator” in this article. Web-Mercator is not exactly conformal and thus not even Mercator. For more infos about this particular issue and a brief history of Web-Mercator read this document. This page explains the general implications different projections have, with focus on software development for logistics applications.

The Vicious Mercator Map Projection

From time to time i am involved in discussions about the pitfalls of the Mercator map projection. Yes, the Mercator projection was invented 1569 for crossing an ocean and not for internet maps. And yes, on a global scale the Mercator projection grotesquely distorts the sizes of nations and continents. You can also argue that this is a discrimination against the southern hemisphere.

But Mercator is great for Developers

Sometimes developers claim they don’t make any projection to avoid distortions. What they actually mean is that they render the latitude and longitude angles of WGS84 directly to the screen. But this “unprojected” projection implies you are handling angles on a sphere like they were points on a plane, and this is also a projection, called equirectangular projection (or in french “plate carrée” and german “Plattkarte”). Like any other map projection the equirectangular projection has specific properties, but it lacks one important property: the conformality.

“Many of the most common and most important map projections are conformal or orthomorphic … in that normally the shape of every small feature of the map is shown correctly… An important result of conformality is that relative angles at each point are correct, and the local scale in every direction around any one point is constant.” John P. Snyder, Map Projections Used by the U. S. Geological Survey, 1983

This is why i always prefer the mercator projection over any non-conformal projection for visualization and computations. The conformality is much more important for logistics applications than comparing the relative size of nations and continents. I also recommend transforming your points to Mercator before doing any geometric computations, because then:

This implies that you can render a geographic circle as a circle on the map canvas. Just divide the mercator radius by cos(center.lat). You see the benefit in the sample on top: The circle of the Karlsruhe “fan” is a circle in the Mercator map, but not in the “unprojected” map.

Plus, you can use 2D geometric algorithms on mercator points, like the computation of voronoi regions.

The Formulas

These are the formulas to project a WGS (lng/lat) point to and from a Mercator point. This is the “Web” version, and we neglect the inaccuracy of Web Mercator, as i mentioned before. The earth radius (6378137.0) is the major axis of WGS84. There’s also a variation that uses the mean between major and minor axis (6371000.0), as used by my company’s web services.

public static Point Wgs2SphereMercator(Point point)
{
    return new Point {
        X = 6378137.0 * point.X * Math.PI / 180.0,
        Y = 6378137.0 * Math.Log(Math.Tan(Math.PI / 4.0 + point.Y * Math.PI / 360.0))
    };
}

public static Point SphereMercator2Wgs(Point point)
{
    return new Point {
        X = (180.0 / Math.PI) * (point.X / 6378137.0),
        Y = (360 / Math.PI) * (Math.Atan(Math.Exp(point.Y / 6378137.0)) - (Math.PI / 4))
    };
}

References

index.html

!LINK.md

L.Map.Sync.js