Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse longitude/latitude of point in Postgis?

The points in Linestring in Postgis (imported from osm by osm2pgsql) is described by the order (longitude, latitude)

for example a Linestring in Munich Map

'LINESTRING(11.4068032 47.8580927,11.4067187 47.8580965)'

How could I reverse the order to normal (latitude, longitude) ? Is (longitude, latitude) very odd order ? Because I see popular Map API all use (latitude, longitude) order

like image 513
Hello lad Avatar asked Feb 10 '23 06:02

Hello lad


1 Answers

You can use ST_FlipCoordinates to return a version of the given geometry with X and Y axis flipped.

Keep in mind, you generally want to keep the axis order (longitude, latitude), which is the correct axis order for PostGIS. Flipping it to (latitude, longitude) will generally break things.

like image 111
Mike T Avatar answered Feb 11 '23 20:02

Mike T