mysqlgeospatialpostgiscoordinate-systemsspatial-query

ST_Transform issue with MySQL


The spatial function ST_Transform returns weird results in MySQL. I tested the following query and compared with PostGIS and obtained very different results:

The query (exactly the same used in MySQL and PostGIS): SELECT ST_AsText(ST_Transform(ST_GeomFromText('POINT(5 45)', 4326), 2154));

I checked with other tools and the result from PostGIS is correct. So why is the result from MySQL so different? I guess it's not a bug or it would have been reported for a while, but then what am I doing wrong with this query?

Note that I tried for multiple lat/lon values and the results are always different, even for POINT(0 0), though the difference is small in this case.


Solution

  • After some more tests and digging, I found the issue: MySQL considers that WKT with EPSG=4326 are given in lat-long while PostGIS considers that they are given in long-lat. This behavior can be customized using the axis-order option for the ST_GeomFromText function in MySQL.

    The MySQL query

    SELECT ST_AsText(ST_Transform(ST_GeomFromText('POINT(5 45)', 4326, 'axis-order=long-lat'), 2154));
    

    returns a result very close to the one with the initial query in PostGIS.