Writing Space & geospatial

Measuring in the wrong coordinate system

The Earth is not flat and your screen is. Every map resolves that by lying in a chosen direction, and the choice of lie determines which questions the map can answer.

This is not a philosophical point. It is why a buffer computed in the wrong coordinate system is wrong by kilometres, and why an area calculation can be off by a factor of three without anything appearing broken.

You cannot have everything

A sphere cannot be flattened without distortion — a consequence of Gauss’s Theorema Egregium, which says that Gaussian curvature is preserved under any isometry. A sphere has positive curvature everywhere, a plane has zero, so no distance-preserving map between them exists. Not difficult; impossible.

What you get to choose is which property survives:

  • Conformal projections preserve angles locally. Shapes look right in small neighbourhoods; areas do not.
  • Equal-area projections preserve area. Shapes distort, sometimes severely.
  • Equidistant projections preserve distance, but only along particular lines.

No projection is conformal and equal-area simultaneously. That is a theorem, not a gap in the catalogue.

Web Mercator, and what it costs

Nearly every web map you have used is in Web Mercator. It is conformal, which is why continents look like themselves and why rotating a map does not shear it. It is catastrophically unequal in area: at 60° latitude the scale factor is about two, so areas are inflated fourfold. Greenland famously appears comparable to Africa while being roughly a fourteenth its size.

For panning and zooming this does not matter. For measuring it matters enormously, and the failure is silent because the library returns a number either way.

Compute the area of a polygon in Web Mercator coordinates and you get square metres that are not square metres. Near the equator the error is small. In Canada or Scandinavia it is a factor of several. Nothing errors; the answer is simply wrong.

Practical note: if you are measuring area or distance, reproject to an appropriate equal-area or local projection first, compute, and only then reproject for display. Measuring in display coordinates is the single most common geospatial error I see, and it produces plausible numbers.

Buffers are the same trap in a different costume

“Everything within 500 metres of this point” sounds simple. In a geographic coordinate system your units are degrees, and a degree of longitude is about 111 km at the equator and zero at the poles. A buffer of 0.0045 degrees is 500 metres in Ecuador and about 250 metres in Stockholm.

The right approach is to project into a system whose units are metres and whose distortion is small over your area of interest — a UTM zone, a national grid, or a local azimuthal projection — buffer there, then reproject. Crossing a UTM zone boundary reintroduces the problem, which is why continent-scale analysis wants an equal-area projection rather than a stack of local ones.

The datum underneath

Projection is only half of it. A projection maps a model of the Earth onto a plane; the datum defines that model — the ellipsoid and how it is tied to physical reference points.

Two datasets in the same projection but different datums will not align. The offsets are typically metres, occasionally hundreds of metres for historical datums. This is invisible at continental zoom and obvious once you are looking at individual parcels, which is exactly when it matters.

The EPSG registry exists to make this tractable: every projection-plus-datum combination has a code, and quoting the code removes the ambiguity that prose descriptions carry. “UTM zone 17N” is underspecified; EPSG:26917 is not.

Practical rules

  • Store data in a geographic system with an explicit datum. Project for analysis and for display, separately, and record which you used.
  • Never measure in Web Mercator. Never buffer in degrees.
  • Carry the EPSG code with the data, not in a README.
  • If two layers disagree by a consistent offset, suspect the datum before you suspect the data.
  • Test with something whose true area you know. A silent factor-of-two is only silent until you check.

The general shape of this is familiar: a coordinate is not a location, it is a location plus a frame, and dropping the frame produces numbers that are precise, confident and meaningless.

References

  1. J. P. Snyder. Map Projections: A Working Manual. USGS Professional Paper 1395, 1987. The definitive reference, with the mathematics of every common projection.
  2. C. F. Gauss. “Disquisitiones generales circa superficies curvas,” 1827. The Theorema Egregium, which is why the trade-off is a theorem rather than an inconvenience.
  3. J. Iliffe, R. Lott. Datums and Map Projections, 2nd ed. Whittles, 2008.
  4. IOGP. EPSG Geodetic Parameter Dataset. The registry of coordinate reference system codes.
  5. J. P. Snyder. Flattening the Earth: Two Thousand Years of Map Projections. University of Chicago Press, 1993. On why particular projections won in particular eras.
← All writing Get in touch →