PostGISMeasurement

ST_DistanceSpheroid

What is ST_DistanceSpheroid?

ST_DistanceSpheroid returns the minimum distance in metres between two longitude/latitude geometries, computed on a user-specified reference spheroid (ellipsoid of revolution). It is more accurate than ST_DistanceSphere at the cost of slightly higher CPU.

SQL
ST_DistanceSpheroid(geometry geomlonlatA, geometry geomlonlatB, spheroid measurement_spheroid)float

The spheroid argument is a spheroid literal of the form 'SPHEROID["name", semi_major_axis, inverse_flattening]'. The WGS84 spheroid is 'SPHEROID["WGS 84",6378137,298.257223563]'.

When would you use ST_DistanceSpheroid?

Use ST_DistanceSpheroid when you need high-accuracy real-world distances from lon/lat geometry data without casting to geography. It is commonly used in geodetic, aviation, maritime, and scientific applications where sub-percent accuracy matters. If you do not need to specify a non-WGS84 spheroid and want index-accelerated proximity queries, prefer geography with ST_Distance/ST_DWithin.

SQL
1SELECT ST_DistanceSpheroid(
2  'SRID=4326;POINT(-122.42 37.78)'::geometry,
3  'SRID=4326;POINT(-73.98 40.75)'::geometry,
4  'SPHEROID["WGS 84",6378137,298.257223563]'
5) AS metres;

FAQs

How accurate is ST_DistanceSpheroid?

Sub-millimetre accurate relative to the specified ellipsoid. Error is dominated by whether the ellipsoid matches the datum of your data, not by the algorithm.

How does it compare with geography's ST_Distance?

Functionally equivalent when the spheroid matches (WGS84). The geography type is more convenient because you do not pass the spheroid explicitly and because it supports GiST index acceleration for ST_DWithin.

What spheroid string should I use?

For WGS84 (the standard for GPS and most global data), use 'SPHEROID["WGS 84",6378137,298.257223563]'. Other common choices include GRS80, Clarke 1866, and Bessel 1841; match your data's datum for best accuracy.

Does it use a spatial index?

No — it is a per-pair function. For index-accelerated thresholded proximity, cast to geography and use ST_DWithin.