# Measuring Distances and Why Projections Matter (+ Practical Examples)

Entering the world of projections can be slightly overwhelming. Basically every projection has advantages and disadvantages. Some may preserve elements of direction, distance or area better or worse than others which is why a careful selection of a suitable projection is so crucial. With this basic tutorial followed by some practical examples we would like to just touch this broad topic and help you understand why and when they matter when you are trying to measure distances or compute areas of interest for analysis.

## Specifying a Location on a Plane requires a Map Projection

Projecting the globes 3D ellipsoid on a plane 2D surface isn't an easy task.
Well mathematically speaking it may be an easy task however you will quickly notice it is impossible to do so by not distorting the shapes and boundaries of the countries, oceans and continents.
To this end there exist all different kinds of projections which use a *Geographic Coordinate System* (GCS) as input.
The GCS subject to a geodetic datum uses a three-dimensional spherical surface to define a location on the earth with the help of longitudes and latitudes in degrees.
Some well known GCS are *The World Geodetic System 84* (WGS84 Datum), *The North American Datum 83* (NAD83 Datum) or *The Ordnance Survey of Great Britain 36* (OSGB36 Datum).
Using the GCS as input the projections themselves are referred to as a *Projected Coordinate Systems* (PCS).

The following image features two different PCS, namely the *Web Mercator Projection* (EPSG:3857) and the *Mollweide Projection* (EPSG:54009) both derived from the *World Geodetic System 84 Datum* (note: there exist many more different types of world projection types such as equidistant PCS which show true distances only from the center of the projection or along a special set of lines).

The former is used in prominent web mapping applications such as Google Maps or Bing Maps which shows areas near the poles as greatly exaggerated. The latter is an equal-area projection which "trades the accuracy of angle and shape for a accuracy of proportions in area" which means that in the distribution of countries in relation to each other is fairly realistic.

On a side note: you might ask yourself why the Web Mercator Projection is so prevalent in web mapping applications? Well, the reason is quite straightforward. Web maps consist of tiles which are square. The Web Mercator Projection is equally square and this way the map tiles fit nicely into a powers-of-two schema as you progress through each successive zoom-level.

Voila, so both of these projections are subject to a cartesian coordinate system (X and Y axes) and both have their units defined in meters. Hence, are the coordinates given as eastings and northings from the origin of the projection which at this point should allow us to start measuring? Well yes but it's treacherous and this is where you have to be careful as both of these projections for example do not preserve distance if you were to calculate the euclidean metric (just compare the image above to your globus on your desk and you will see).

What we should be looking at are larger scale PCS as uniform (national) grids which will yield realistic & trustworthy distance results.

## So How Do Grids Work?

The fundamental concept of how grids including their eastings and northings work is the same, so let's pick one tangible example.

If we for example have a map dataset of the United Kingdom and we want to compute distances between locations which could be cities, we should make sure that our projection suits the region, e.g. the *British National Grid (BNG)* (EPSG:27700) derived from the OSGB36 Datum.
Each grid cell (square) features an identifier which consists of 2 grid letters, the first being the identifier of the 500 x 500 km square it belongs to.
5 of these exist, namely `S`

, `T`

, `N`

, `H`

and `O`

.
These parent squares are then again subdivided into 25 further squares of 100 x 100 km size which is depicted by the second letter from `A-Z`

starting in the north-west corner of the grid and `Z`

being in the south-east corner.
The following image should help you comprehend.

Let's focus on Cornwall which lies in the `SW`

square.
Obviously this 100 x 100 km square can be broken down into a smaller grid.
For the sake of example we have added the BNG 10 x 10 km grid which is depicted by rows and colums from south-west to north-east and the first being `SW00`

.
The city of *Penzance* (who doesn't love The Pirates of Penzance...) can be found in `SW42`

which is the second row and fourth column.
This `SW`

grid cell is located 100 km east of the south-west origin of SV (easting 0, northing 0).
It's south-west point is at (easting 100, northing 0), it's south-east point is at (easting 200, northing 0), it's north-west point is at (easting 100, northing 100) and *Penzance* features an easting of `147092`

and a northing of `030263`

, telling us it's 147 km east and 30 km north from our origin which is in `SV`

(or just simply: `SW 47092 30263`

).

Similarly to the British National Grid PCS each country may have their own grid(s) which are suitable for describing locations on a plane without distortions and computing spatial information, e.g. the United States National Grid. There also exists (The Universal Transverse Mercator coordinate system (UTM))[https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system] which features zones uniform over the globe and is also suitable for measurements.

## Comparisons, yes please!

By now you are probably interested to see if there really exist differences in the spatial calculations of distances that we were talking about earlier.
For the sake of completeness we have also added the *Haversine Formula*, also know as the *The Great Circle Distance* which can be used to measure distances between points from coordinates given in degrees (latitude and longitude).

In this following example we will be computing straight line distances between Penzance and London in PostGIS with different projections to emphasize the importance of choosing wisely. The input coordinates are given in EPSG:4326 as latitude and longitude.

### EPSG:3857

Using Web Mercator Projection```
SELECT round(CAST(
ST_Distance(
ST_Transform('SRID=4326;POINT(-5.539267 50.118445)'::geometry, 3857),
ST_Transform('SRID=4326;POINT(-0.127724 51.507407)'::geometry, 3857)
)/1000 As numeric),
2);
```

650.22 kilometers.

### EPSG:54009

Using World Mollweide (equal area)```
SELECT round(CAST(
ST_Distance(
ST_Transform('SRID=4326;POINT(-5.539267 50.118445)'::geometry, 54009),
ST_Transform('SRID=4326;POINT(-0.127724 51.507407)'::geometry, 54009)
)/1000 As numeric),
2);
```

435.82 kilometers.

### EPSG:54008

Using World Sinusoidal (equal area & equidistant along parallels)```
SELECT round(CAST(
ST_Distance(
ST_Transform('SRID=4326;POINT(-5.539267 50.118445)'::geometry, 54008),
ST_Transform('SRID=4326;POINT(-0.127724 51.507407)'::geometry, 54008)
)/1000 As numeric),
2);
```

416.98 kilometers.

### EPSG:4326

Using WGS84 with Haversine's Formula (Great Circle Distance)```
SELECT round(CAST(
ST_DistanceSpheroid(
'SRID=4326;POINT(-5.539267 50.118445)',
'SRID=4326;POINT(-0.127724 51.507407)',
'SPHEROID["WGS 84",6378137,298.257223563]'
)/1000 As numeric),
2);
```

411.39 kilometers.

### EPSG:32630

Using UTM zone 30N```
SELECT round(CAST(
ST_Distance(
ST_Transform('SRID=4326;POINT(-5.539267 50.118445)'::geometry, 32630),
ST_Transform('SRID=4326;POINT(-0.127724 51.507407)'::geometry, 32630)
)/1000 As numeric),
2);
```

411.28 kilometers.

### EPSG:27700

Using British National Grid```
SELECT round(CAST(
ST_Distance(
ST_Transform('SRID=4326;POINT(-5.539267 50.118445)'::geometry, 27700),
ST_Transform('SRID=4326;POINT(-0.127724 51.507407)'::geometry, 27700)
)/1000 As numeric),
2);
```

411.31 kilometers.

### EPSG:28355

Using a grid suitable for Australia```
SELECT round(CAST(
ST_Distance(
ST_Transform('SRID=4326;POINT(-5.539267 50.118445)'::geometry, 28355),
ST_Transform('SRID=4326;POINT(-0.127724 51.507407)'::geometry, 28355)
)/1000 As numeric),
2);
```

433.65 kilometers (which is of course way off for the UK but would be very suitable for measuring distances in Melbourne or Sydney!).

### EPSG:27700

Measuring in QGIS withWe believe the message should be clear.
*A rule of thumb* for choosing a suitable projected coordinate system as Robin Lovelace in *Geocomputation with R* has pointed out nicely is:

The choice should always depend on the properties that are most important to preserve in the subsequent creation of maps of analysis.

## Further Reading Links

**Post history - Last 5 commits**

**02/04/2020 23:39:16** - testing flavoured markdown for images (Timothy Ellersiek)

**01/04/2020 23:01:20** - coordinate systems and projections tutorial (Timothy Ellersiek)