Coordinates & distance

Latitude and longitude as numbers: haversine and geodesic distance, bearings, destination points, great circles, DMS and UTM conversion, radius and nearest searches, and the time zone, country and elevation of a coordinate.

Left, great-circle routes from London Heathrow to New York, Tokyo, Sydney, São Paulo, Los Angeles and Johannesburg over the 1,172 large airports of OurAirports as grey dots; right, the length of one degree of longitude on the WGS84 ellipsoid every 10 degrees of latitude, falling from 111 km at the equator to 19 km at 80 degrees. coordinates are angles: the shortest path curves, and a degree shrinksgreat circles from Heathrow over 1,172 large airports0°10°20°30°40°50°60°70°80°km in 1° of longitude: 111 at 0°, 56 at 60°, 19 at 80°

Latitude and longitude are angles, not x and y, and most errors with coordinates come from forgetting it. The guides here do the everyday calculations on raw coordinates in Python: haversine and ellipsoidal distance, bearings, destination points and range rings, midpoints and great-circle paths, DMS and UTM conversion, radius and nearest-neighbour searches with a BallTree, and the time zone, country and elevation of a point, with the fixes for radians, lost hemispheres, wrong UTM zones, buffers in degrees and truncated decimals.

Every number comes from a run on open data, mostly the 80,000 places of OurAirports and the US Geological Survey’s names for Hawaii. Haversine is within -0.38% to +0.56% of the ellipsoid for 19,981 random pairs; a half-degree buffer covers 9,649 km² at Singapore but 4,701 km² at Anchorage; float32 storage moves points by up to 0.84 m; and the 90 m elevation model puts Everest 125 m short.

🧭 Start with the concepts

The ideas the how-to guides below assume you already have.

⚙️ Then do the task

Step-by-step walkthroughs with code you can copy and adapt.

Show every how-to guide in this topic

🔧 When it breaks

The errors this topic produces, with the cause explained rather than just the command.

Related topics

Subjects that keep coming up alongside this one, most overlap first.

Keep browsing

Coordinates & distance sits in Geometry & space. Every topic on the site is listed on the topics index.