3
SELECT ST_Distance(gg1, gg2) As spheroid_dist, ST_Distance(gg1, gg2, false) As sphere_dist
FROM (SELECT
    ST_GeographyFromText('SRID=4326;POINT(37 -122)') As gg1,
    ST_GeographyFromText('SRID=4326;POINT(48 2)') As gg2
    ) As foo  ;

--> ERROR: Coordinate values are out of range [-180 -90, 180 90] for GEOGRAPHY type

I understand those points are pretty distant (San Franciso vs Paris, France), but how can I get the distance calculated between those two?

8

The problem is that you've got the wrong coordinate order. WKT for SRID 4326 is longitude then latitude (think Cartesian, it is X then Y). The error is telling you that -122 is not a valid latitude.

The geometry (or geography) needs to look like:

SELECT ST_GeographyFromText('SRID=4326;POINT(-122 37)')...

SELECT ST_GeographyFromText('SRID=4326;POINT(2 48)')...
0

By skimming the query, I guess that you missed to add "foo" :

SELECT ST_Distance(foo.gg1, foo.gg2) As spheroid_dist, ST_Distance(foo.gg1, foo.gg2, false) As sphere_dist
FROM (SELECT
    ST_GeographyFromText('SRID=4326;POINT(37 -122)') As gg1,
    ST_GeographyFromText('SRID=4326;POINT(48 2)') As gg2
    ) As foo  ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.