PostGISMeasurement

ST_DistanceSphere

What is ST_DistanceSphere?

ST_DistanceSphere returns the minimum great-circle distance in metres between two longitude/latitude points on a sphere of Earth-like radius (6370986 m). It is a fast, lightweight alternative to the more accurate ST_DistanceSpheroid or the geography type.

SQL
ST_DistanceSphere(geometry geomlonlatA, geometry geomlonlatB)float

Input must be in a geographic CRS (longitude/latitude). Result is always in metres. Typical error relative to the WGS84 spheroid is around 0.3% — good enough for many everyday proximity queries but not surveying-grade.

When would you use ST_DistanceSphere?

Use ST_DistanceSphere when you have lon/lat geometry (not geography) and want a real-world metre distance without casting or reprojecting — for quick reports, approximate proximity sorts, or back-of-envelope analytics where sub-percent accuracy is unimportant. It is faster than ST_DistanceSpheroid and faster than ST_Distance on geography with use_spheroid = true, at the cost of minor accuracy loss.

SQL
1SELECT name, ST_DistanceSphere(
2  geom,
3  ST_SetSRID(ST_MakePoint(-73.98, 40.75), 4326)
4) AS metres_from_times_square
5FROM cafes
6ORDER BY metres_from_times_square
7LIMIT 10;

FAQs

How accurate is ST_DistanceSphere?

Roughly 0.3% error compared with a spheroidal calculation — the Earth is modelled as a perfect sphere of radius 6370986 m. Acceptable for most analytics, inadequate for surveying or aviation navigation.

When should I use ST_DistanceSphere vs ST_DistanceSpheroid vs geography?

Use ST_DistanceSphere for speed and when 0.3% error is fine. Use ST_DistanceSpheroid (or ST_Distance on geography with use_spheroid = true) when you need spheroidal accuracy. Prefer geography when you also need index-accelerated proximity queries (ST_DWithin).

Does it support non-point geometries?

Historically ST_DistanceSphere accepted only points, but modern PostGIS (2.2+) accepts any geometry types and computes the minimum great-circle distance between them — still assuming a spherical Earth.

Does it use a spatial index?

No. It is a per-pair computation with no index support. For index-accelerated proximity queries on lon/lat data, cast to geography and use ST_DWithin.