Geo Distance vs ST_DistanceSphere

114 views
Skip to first unread message

Barrett Clark

unread,
Mar 23, 2016, 8:46:23 PM3/23/16
to RGeo-Users
I'm trying to compare the distance calculation that RGeo performs to ST_DistanceSphere. I thought they should give the same result given a spherical factory, but they don't. I'm hoping someone can help me understand why.

Here is what I'm doing:

Using RGeo:
factory = RGeo::Geographic.spherical_factory(:srid => 4326)
point_sfo = factory.point(-122.3748433, 37.61900194)
point_lga = factory.point(-73.87260917, 40.77724306)
distance_meters = point_sfo.distance(point_lga)
distance_miles = distance_meters * 0.000621371
=> 2575.9719632552024

Using PostGIS:
SELECT ST_DistanceSphere(
  ST_GeomFromText('POINT(-122.3748433 37.61900194)',4326), -- SFO
  ST_GeomFromText('POINT(-73.87260917 40.77724306)',4326)  -- LGA
)::NUMERIC * 0.000621371 AS dist_miles

2573.09304783170447076

Thank you,
Barrett

Court Simas

unread,
Jun 1, 2017, 2:09:19 PM6/1/17
to RGeo-Users
I, too, would love to know what's going on here.
Reply all
Reply to author
Forward
0 new messages