I want to get the nearest neighbour information for a point, and I'm getting different results based on different geometry/geography types. Assuming I only care about the most accurate result, which version should I use?
- Using a sphere:
SELECT ('SRID=4326;POINT(-95.1212742 29.5574348)'::geography <-> 'SRID=4326;POINT(-91.0717865 30.3703801)'::geography)/1000 --RETURNS 400.40
- Using a planar distance (not sure what that means for ESPG:4326):
SELECT ST_Distance('SRID=4326;POINT(-95.1212742 29.5574348)'::geometry, 'SRID=4326;POINT(-91.0717865 30.3703801)'::geometry) --RETURNS 4.130
<- this is identical to using<->
operator on geometry type. - Using a projected coordinate system:
SELECT ST_Distance('SRID=4326;POINT(-95.1212742 29.5574348)'::geography, 'SRID=4326;POINT(-91.0717865 30.3703801)'::geography)/1000 --RETURNS 401.09
<- geodesic distance based on SRID
We can ignore #1 because it uses the fastest spherical calculation. However, for the last two, I get diverging results given different neighbour points, and I'm not sure which one is the more accurate one:
SELECT ST_Distance('SRID=4326;POINT(-95.1212742 29.5574348)'::geometry, 'SRID=4326;POINT(-91.1505645 30.6506557)'::geometry) --RETURNS 4.118
SELECT ST_Distance('SRID=4326;POINT(-95.1212742 29.5574348)'::geography, 'SRID=4326;POINT(-91.1505645 30.6506557)'::geography)/1000 --RETURNS 401.42
SELECT ST_Distance('SRID=4326;POINT(-95.1212742 29.5574348)'::geometry, 'SRID=4326;POINT(-91.0717865 30.3703801)'::geometry) --RETURNS 4.130
SELECT ST_Distance('SRID=4326;POINT(-95.1212742 29.5574348)'::geography, 'SRID=4326;POINT(-91.0717865 30.3703801)'::geography)/1000 --RETURNS 401.09
#2 Returns 2D Cartesian (planar) distance between two geometries, in projected units. Considering EPSG:4326 is not a planar CRS, this will return result in degrees, which would be less accurate?
#3 returns geodesic distance based on SRID, which should be most accurate?