Projections and datums in
web mapping: an introduction


Lyzi Diamond | NACIS 2017 | Montreal, QC
This talk is based on a blog post I wrote, so don't scramble to write everything down.
This talk:
  1. A reintroduction to projections and datums (aka geodesy)
  2. An overview of the coordinate systems we use in web mapping
  3. An impassioned defense of spherical mercator (maybe)
  4. Lots of bad doodles by yours truly (not an artist)
1. Projections, datums, coordinate systems, WHY?!
A truth: Maps are tools for communication In the cartography context, we think about communicating specific types of information visually on the map. But the visual map is only a small part of what geospatial technology allows us to do. Spatial data is used to find places, calculate distances, analyze phenomena. The visual output is great and important, but underneath it is a bunch of other information that is also important and without it, we would be lost. Literally and figuratively.
In order to communicate about physical locations, we need to have a common system that we can use as a guide.
In our mappy world, these are called coordinate reference systems, and they determine how maps look, how data is stored, and how distance is calculated. "Walk three blocks and then turn left" doesn't work as well if you don't know where the directions are starting from.
How do these reference systems come to be? Well I sure am glad you asked!
Geodesy: measuring the earth

What does the Earth look like?
A sphere? Nope.
A spheroid? Nope.
An ellipsoid? Nope.
Its own weird crazy shape? Yes! (thx 4 this img Mike Foster)
in reality the earth is its own crazy wonky lumpy shape that is constantly changing in four dimensions with mass movements and human behavior. It also has inconsistent density (and thus an inconsistent gravitational pull), making it even harder to model.
The real shape of the earth is too complex to be useful as a reference for measurement.
Instead, we use a reference ellipsoid to approximate the planet's surface. Instead, we use a reference ellipsoid as an approximation of the surface of the earth. A reference ellipsoid is a mathematically-defined surface that roughly matches the model of the earth when its topographical features are removed (the lovely lumpy geoid, a model of the earth with assumed equal density).
Just like in dating, the perfect mathematical ellipsoid does not exist.
There is not a single canonical ellipsoid that is used to measure the earth at every location. Because a reference ellipsoid is an approximation, there are locations where an ellipsoid exactly matches the geoid and there are locations where an ellipsoid is way way off. In some of these locations, a different reference ellipsoid is used that better matches the earth’s surface at those locations.
Okay, so now we've picked our reference ellipsoid. What's next?
Puppies!
Once we've defined our reference ellipsoid, we have a shape on which we can place a coordinate system.
A coordinate system defines locations on that surface that can be used as reference points for measurement. This is huge — imagine trying to tell someone how to get to your house without using miles, meters, or any other standardized system of measurement. Imagine trying to assess property values without the concept of acres and square footage. A coordinate system is a way to standardize the way we describe locations on a map. It’s the common understanding that allows a person to go out in the world, measure some stuff, and know with confidence that the measurements they took will show up in the right place on any map that anyone creates with that data.
Coordinate systems let us do this:
There are two types of coordinate systems:
Geographic coordinate systems are a combination of three things:
  1. A unit of measurement for angles (we use degrees)
  2. A prime meridian
  3. A geodetic datum
When we use terms like longitude and latitude, we're referring to locations using a geographic coordinate system.
The datum is the mathematical equation that connects our reference ellipsoid to the Earth's surface.

Because, as we discussed before, the reference ellipsoid is not related to the Earth's surface in a regular way in every location, certain datums are going to work better for different parts of the planet just as certain ellipsoids work better for different parts of the planet.
Projected coordinate systems are like geographic coordinate systems, but different.
They are also a grid used as a reference for locations on the planet, but translate the three-dimensional grid to a two-dimensional plane (like a piece of paper or a screen).
One way to visualize it is to imagine a light emanating out from the center of that reference ellipsoid, and a piece of paper is wrapped around that ellipsoid, whether in a cone, or in a cylinder, or some other shape. The places where the shadows from the coordinates appear on that piece of paper defines the projection, and when you unwrap the paper and lay it flat again, those points the coordinate system for your projected data.
A projected coordinate system is the mathematical definition of a projection.Note: a projected coordinate system includes a lot more definitions than just the projection. These include the center of the projection, scale factor, and others.
Not discussed here: vertical coordinate systems.
Mid-talk recap:
2. Okay. So what about web maps?
WAIT FIRST:
1.5. What are these EPSG codes I keep hearing about?
European Petroleum Survey Group
Quick note on naming: coordinate systems (projected and geographic) are often identified by an EPSG code. EPSG stands for European Petroleum Survey Group, an organization involved in best practices for surveying and applied geodesy. In 2005, EPSG was absorbed into the International Association of Oil & Gas Producers (IOGP), but the list of coordinate systems they maintained is still called the EPSG Geodetic Parameter Dataset.
2. Okay. So what about web maps?
There are two coordinate systems we need to think about when it comes to web maps: EPSG:4326 (WGS 84) and EPSG:3857 (Web Mercator/Pseudo Mercator). They are both used in web mapping, but in different ways.
WGS 84 (World Geodetic System of 1984; EPSG: 4326) is the geographic coordinate system (the three-dimensional one) used by GPS to express locations on the earth. Also used in GeoJSON. WGS84 is the defined coordinate system for GeoJSON, as longitude and latitude in decimal degrees. For the most part, when you describe a lon/lat coordinate location, it’s based on the EPSG:4326 coordinate system. This is how we store data at Mapbox and how data should be stored for web mapping.
There is no way to visualize the WGS84 coordinate system on a two-dimensional plane (map), so most software programs project these coordinates using an equirectangular projection (Plate-Carrée).

Web Mercator (or Pseudo Mercator; EPSG:3857) takes the WGS 84 coordinate system and puts it on a square.

But not all of it! The bounds of Web Mercator are limited to approximately 85.06º North and South latitude.
Web Mercator was first introduced by Google (web mapping pioneers) and is used in almost 100% of web maps, but it is strange.
It uses the WGS 84 coordinate system, which uses the WGS 84 ellipsoid, but then goes another step and projects the coordinates onto a sphere.
Two ellipsoids?!
Why Web Mercator? Pros:
"[T]echnology is a result of its environment and requirements, not any absolute value: spherical mercator fits the role of a simple, fast, pannable, and zoomable projection like no other common projection." - Tom MacWright
Cons: which means software programs have to improvise. And when software programs improvise, there is no way to know if the coordinates are consistent across programs. This makes EPSG:3857 great for visualizing on computers (have I mentioned computers dig squares) but not reliable for data storage or analysis.
So. What do we do?
We store data in WGS 84 (EPSG:4326), but display it in Web Mercator (EPSG:3857).
(Yes, that's what we've been leading up to.)
What does this mean for you when making web maps?
1. If you're making a (typical) web map, store your data in geographic (unprojected) coordinates.
2. Do not store your data in Web Mercator, especially if you're trying to do analysis on it.
3. If someone says they want to see their data in WGS 84, project it onto Platte-Carré for them. (Then maybe ask them why they want that.)
4. If you're upset that you can't easily make web maps in other projections, guess what? You can! Just not with out-of-the-box, point-and-click tools.
Ultimately, these standards allow us to use geospatial data more deeply: they give us a common system to communicate, build tools, and grow/learn/play together in harmony.

So when you're upset about Web Mercator, remember that we're using it for the greater good! 💕💖💗
Thanks!
I am @lyzidiamond on Twitter Go to lyzidiamond.com/nacis-2017 for slides