Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lon/Lat Order when using spatial POINT type with MySQL

Tags:

mysql

point

What is the correct order when setting a POINT in MySQL?

Even the answers in SO questions differ on this: Moving lat/lon text columns into a 'point' type column

Is it

POINT(lat lon)

or

POINT(lon lat)

As far, as i see it, it should be the first version (lat lon) as the POINT takes as params x and y, but i was not able to find an definite evidence.

like image 320
madc Avatar asked Jun 18 '12 12:06

madc


2 Answers

as one can see here https://stackoverflow.com/a/5757054/1393681 the order is (lon lat).

lon is basicly the y axis and lat the x if i look at my globe, but the lon's are traveling along the x axis and the lat's along the y axis so i think thats the reason why you use (lon lat)

Despite that, if you stay consistent in your application it shoudn't matter if the world is flipped inside your db ;-)

like image 186
mons droid Avatar answered Oct 21 '22 12:10

mons droid


Seems like lat lon to me. You can check this from your mysql shell:

mysql> SELECT ST_ASTEXT(coords), ST_LONGITUDE(coords), ST_LATITUDE(coords) FROM table;

+----------------------------+-----------------------+----------------------+
| ST_ASTEXT(coords)          | ST_LONGITUDE(coords)  | ST_LATITUDE(coords)  |
+----------------------------+-----------------------+----------------------+
| POINT(33.520571 -18.20072) | -18.20072             | 33.520571            |
+----------------------------+-----------------------+----------------------+

Note: SRID 4326 used.

See also: https://dev.mysql.com/doc/refman/8.0/en/gis-point-property-functions.html#function_st-latitude

like image 24
Palisand Avatar answered Oct 21 '22 11:10

Palisand