Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.
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?

share|improve this question
    
On my PostgreSQL 9.3, PostGIS 2.1.1 system I instead get NOTICE: Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY. –  Craig Ringer Feb 11 at 0:26
    
Did you search for the error? See gis.stackexchange.com/q/76092/12379, gis.stackexchange.com/q/24194/12379 . –  Craig Ringer Feb 11 at 0:27
add comment

2 Answers 2

up vote 6 down vote accepted

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)')...
share|improve this answer
add comment

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  ;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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