Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a latitude/longitude pair into a PostGIS geography type?

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?

like image 719
DRMacIver Avatar asked Mar 26 '10 13:03

DRMacIver


People also ask

How do you convert grid coordinates to geographic coordinates?

World Map ConversionDivide the length of the x-axis by 180 and the y-axis by 90. This will give you the equivalent of each latitude (LA) and longitude (LO) angle in inches. Mark the coordinates of a location on the two axes.

How is latitude and longitude related to geography?

Similar to latitude, the corresponding measurement of distance around the Earth is called longitude. The imaginary lines of latitude and longitude intersect each other, forming a grid that covers Earth. The points of latitude and longitude are called coordinates, and can be used together to locate any point on Earth.

What is PostGIS geography?

geography is a spatial data type used to represent a feature in geodetic coordinate systems. Geodetic coordinate systems model the earth using an ellipsoid. Spatial operations on the geography type provide more accurate results by taking the ellipsoidal model into account.


1 Answers

...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.

like image 67
DRMacIver Avatar answered Sep 28 '22 03:09

DRMacIver