Opened 10 years ago

Closed 10 years ago

#2847 closed defect (invalid)

ST_DISTANCE between geography points incorrect

Reported by: rotten Owned by: pramsey
Priority: high Milestone:
Component: postgis Version: 2.1.x
Keywords: Cc:

Description

It appears that ST_DISTANCE is computing distances incorrectly between geographic points, at least in the version I have (below).

Consider this query which compares the distance between my office and a nearby pub, versus my office and a nearby baseball stadium:

select

ST_DISTANCE(st_geographyfromtext('POINT(39.982708 -83.008314)'),

st_geographyfromtext('POINT(39.983736 -83.014097)')) as "office to harrisons",

ST_DISTANCE(st_geographyfromtext('POINT(39.982708 -83.008314)'),

st_geographyfromtext('POINT(39.968347 -83.010781)')) as "office to clippers"

office to harrisons office to clippers 645.98070299200003300 337.65466923299999300

When I measure these with a ruler in Google Earth I get about 500 meters for the first one and about 1580 meters for the second one.

I've tried this with spheroid == false, and while the actual measurements are slightly different they are incorrect as well.

I also tried explicitly setting the SRID. That didn't really change anything.

I searched the tickets and did not see this particular issue called out, although there appear to be a recently fixed, related ticket with ST_DISTANCE and geography polygons, but that was a few releases ago…

This has thrown off a whole bunch of calculations I've been running. Everything looked good until we actually mapped some of the points today and realized the distances were wacky. :-( .

select PostGIS_full_version();

POSTGIS="2.1.3 r12547" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.9.2, released 2012/10/08" LIBXML="2.7.8" LIBJSON="UNKNOWN" RASTER

select version();

PostgreSQL 9.3.2 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, 64-bit

Change History (1)

comment:1 by pramsey, 10 years ago

Resolution: invalid
Status: newclosed

Your longitude and latitude are reversed, unless your office happens to be near the South pole. Use

SELECT
ST_DISTANCE(st_geographyfromtext('POINT(-83.008314 39.982708)'),
st_geographyfromtext('POINT(-83.014097 39.983736)')) as "office to harrisons",
ST_DISTANCE(st_geographyfromtext('POINT(-83.008314 39.982708)'),
st_geographyfromtext('POINT(-83.010781 39.968347)')) as "office to clippers"
Note: See TracTickets for help on using tickets.