Map Projections and Coordinates
Programmer's Guide to Web Mercartor
Table of Contents
Table of Contents
-
Projection Distortion
The issues of projecting a spherical onto a plane surface
-
Geodetic Datum
What actually is a Geodetic Datum & the recipe to create one
-
Order of Longitude & Latitude
Do we write [lon,lat] or [lat,lon]?
-
Web Mercator
The projection for the web map
-
EPSG Numbers
The EPSG numbers you should know
Projection is the technique to display 3-dimensional data from the real world on a 2-dimensional map.
It is the way in which the spherical, curved surface image of our glove is transformed to planar image.
Unrolling the curved surface of the earth onto a flat image is complex, and we need to understand the image distortion that come with it.
Projection Distortion & Deformation
The most common approach to display the surface of our globe onto a flat map is the Mercartor Projection. In unwraps the globe by cutting the sphere over one meridian (straight line from north to south) and unrolls the equator onto the flat surface. The resulting width of the flat plane is equal to the circumference at the equator. The areas north and south to the equator are stretched to fill the rectangular image: The further away the area is from the equator, the more stretched and distorted it is.
Geodetic Datum
Geodetic Datum or Geodetic System is the fancy word for Coordinate System -
but sometimes it is also called Coordinate Reference System or CRS. 🤦
It defines how a location on earth is described in numbers and letters. We call these numbers
coordinate.
The use of the words coordinate (singular) and coordinates (plural) is confusing.
Technically, the set of n numbers which describe one location is called "coordinate".
If we have m different locations (m•n numbers) we say
coordinates.
This is not super strict, but keep it in mind when naming variables and classes in your code.
Defining a coordinate system involves three components:
-
Reference Ellipsoid
Our earth is not a perfect sphere. To be honest: It is more like a giant potato. Describing the exact shape is very complex. So the goal of every coordinate system (aka Geodetic Datum) is to create an approximation good enough for practical purposes, but with a level of complexity that is still usable. For most applications, an ellipsoid does the job.
A reference ellipsoid is defined by its geometric attributes: Radius and Eccentricity.
Eccentricity: The ratio between the globe's radius at the equator and at the poles.A meridian is a line of points with the same longitude. Meridians connect the poles and are aligned North to South. They all share the same length.
A parallel is a line of points with the same latitude. All parallels are parallel to each other - hence the name. They vary in length: The equator is the longest parallel - the closer to a pole, the shorter the parallel.
-
Format of Coordinates
The format of a coordinate is the norm of how a location is described in numbers. The most common form is longitude (degrees East/West) and latitude (degrees North/South). Most digital systems record longitude and latitude in two decimal numbers. For instance, the longitude/latitude of Dubai is 55.287/25.264. To get the exact location in 3D space, we also have to add the height over the ellipsoid.
There are coordinate systems which do not use longitude and latitude. For example Military Grid Reference System (MGRS) divides the ellipsoid into a grid structure of zones and sub-zones. -
Points of Reference
This step sets the origin of the coordinate system: Deciding which location is the zero coordinate.
The zero for latitude (North/South) is the equator. This makes sense because the equator is the plane of the earth's rotation, perpendicular to the axis of rotation. It is the longest parallel.
The zero for longitude (East/West) is called the prime meridian. It is chosen arbitrarily. In old times, different countries had their own definition of the prime meridian. Today, the internationally agreed standard is the meridian crossing the Royal Observatory in Greenwich, United Kingdom.
Usually, the prime meridian is the center of world Mercator maps. For unwrapping those maps, the globe is usually cut at the meridian opposite the prime meridian. These maps have the nice side-effect that they cut through the Pacific ocean over the Bering Straight. Also, the date-line on the opposite side of the prime meridian runs (mostly) through the middle of the Pacific ocean.
Web Mercator
When Google launched its map service in 2005, they had to pick a geodetic
datum.
WGS84 was the obvious
choice since most Location Based Services will be based on GPS which uses WGS84.
However, Google is using a simplified Reference
Ellipsoid:
It uses a perfect sphere as a model of the globe.
This has two implications:
- Projection Error: The map location deviates from ellipsoidal Mercator maps. This error increases with distance from the equator. This error makes Web Mercator projection unusable for use cases that require accurate geo-positioning. However, it is sufficient for most uses of web mapping: Turn-by-turn navigation or locating the nearest restaurant.
- Simplified Projection: Treating the underlying globe as a perfect sphere means that the maths to convert between geo-coordinates (Longitude & Latitude) and x/y pixel coordinates of the map is greatly simplified. This benefits thin clients like browsers and handhelds for coordinate calculations.
Because of using a sphere instead of an ellipsoid, Web Mercator is also called Spherical Mercator. Because geodesic professionals like to point out its faults, they call Web Mercator Pseudo Mercator. And since it was invented by Google, it is also known as Google Web Mercator.
EPSG Registry
To overcome the confusion of a myriad of different Coordinate Reference Systems and names, the oil & gas industry has come up with a database to catalog them. This is the EPSG registry. The registry records the definition of the Coordinate Reference System and catalogs under a unique number called Spatial Reference System Identifier (SRID).
Here are two important EPSG entries that you need to know:
EPSG:4326 - WGS 84
The EPSG entry for WGS84 geodetic datum.
WGS84 are the latitude/longitude coordinates ubiquitous to all Location Based Services.
It is a Geographic Coordinate System as it is defined over the underlying sphere
approximating the earth's actual shape.
EPSG:3857 - Spherical Mercator
The EPSG entry for the x/y coordinate system for flat web-maps.
EPSG:3857 uses projected x/y coordinates which are defined over a flat 2D map -
after projecting the sphere to the 2D surface.