0

I have a table of cities that includes the name and location of that city.

CREATE TABLE cities (
    name        varchar (255),
    location    GEOGRAPHY(Point)
)

For certain cities, I'll set the location:

UPDATE cities SET location='POINT(32.4543 -99.7384)' WHERE slug='abilene';

But when I retrieve the longitude and latitude for that location, it is different than the value I inserted:

select ST_X(location::geometry),ST_Y(location::geometry) from cities where slug='abilene'

The ST_X is correct at 32.4543 but the ST_Y is incorrect at -80.2616

Why is the latitude different than the value I inserted?

I am using PostgreSQL 9.6.9 and Postgis 2.5

1
  • Read postgis.net/docs/…: If you do not specify an SRID, the SRID will default to 4326 WGS 84 long/lat will be used, and all calculations will proceed using WGS84. Latitude can't be -99.7384. – user30184 Apr 2 '20 at 20:18
4

Coordinates must be expressed as longitude first, then latitude.

Instead of throwing an error when PostGIS receive a latitude of -99 degrees, it makes some artistic computation to try to locate the point on the earth surface (like going on the other side of the pole).

--> fix your coordinates order

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.