views:

630

answers:

2

I'm trying to load a bunch of latitude/longitude pairs into a PostGIS geography type so as to be able to query by location.

In particular I have a table with float latitude and longitude columns and a geography(Point, 4326) column. I would like to do

update mytable set geography = ???

The documentation appears to suggest that the following should work:

update mytable set geography = ST_GeogFromText('POINT(' || latitude || ' ' ||
                                                           longitude || ')');

It doesn't. I don't know what it's interpreting this point as meaning, but it only allows the longitude to lie between -90 and 90, so it's clearly not a longitude.

So, what do I do?

+1  A: 

...sigh. Stupidity on my part. Apparently the correct order is longitude, latitude. I was fooled into thinking that both coordinates had the same range (-180 to 180) so thought something more subtle was going on.

DRMacIver
mark your answer as accepted.
Evan Carroll
A: 

Thank you, Evan!

I kept getting the following error in Django using GIS/GeoDjango:

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

It turns out the problem was exactly what you described. With geometry fields, the point field was formatted POINT(LAT LNG), but with geography fields, it's POINT(LNG LAT).

intrepidweb