Repository navigation
Description
Describe the bug
After upgrading to MySQL 8, using data with a geographic SRID (specifically, 4326) causes phpMyAdmin to behave incorrectly when visualizing GIS data.
To Reproduce
Steps to reproduce the behavior:
- Have a table with properly formatted spatial data in a geographic SRS.
- Select some data from the table.
- Click the "Visualize GIS Data" button below.
- The map may temporarily draw something that appears to be a shape, but then blanks out.
Expected behavior
One would expect the shape to be rendered correctly.
Server configuration
- Operating system: CentOS 8
- Web server: Apache 2.4
- Database version: 8.0.18
- PHP version: 7.3.13
- phpMyAdmin version: 5.0.1
Client configuration
- Browser: Safari 13.0.5
- Operating system: Mac OS X 10.15.3
Additional context
This happens specifically when using a geographic SRS. It's worth noting that MySQL 8 uses and analyzes the SRID much more so than 5.7 did. In MySQL 5.7, the SRID was essentially ignored, so that if one wanted to store the location of the Topeka Zoo in Topeka, KS, for example, you would store it as ST_GeomFromText('POINT(-95.726760 39.055857)'), with the X coordinate (longitude) first, followed by the Y coordinate (latitude). It treated all coordinate systems as Cartesian coordinates with SRID 0. MySQL 5.7 at least checked that all SRIDs involved in an operation were the same, but did not otherwise use it. MySQL 5.6 and earlier versions didn't even do that.
MySQL 8 has a better understanding of SRSes, and when using an SRS system that represents geographic coordinates, rather than Cartesian coordinates, it expects points in the regular format: latitude, then longitude. So the Topeka Zoo would be created as ST_GeomFromText('POINT(39.055857 -95.726760)', 4326). (If you were to try to store geometric data using the 5.7 method of X, then Y, MySQL 8 complains that it's not valid GIS data for the spatial reference system specified, because there's no such thing as 95°S.) But however phpMyAdmin is retrieving the data and sending it to the map, I don't think it understands this distinction. It's appears to be treating MySQL 8 geographic data as Cartesian data, which is probably why it starts drawing a shape, gets to a point that's more than 90°W, then craps out because that doesn't make sense, all while pointing the map at Antarctica. It's getting the latitude and longitude flipped.
Activity
williamdes commentedon Mar 4, 2020
Thank you for report and details
I really appreciated
Could you send a test table with test data?
btacordex commentedon Mar 4, 2020
Here's a dump file that should recreate it. Looking at the data in WKT format, it looks like it doesn't actually hit 90°W, but it does come pretty close.
williamdes commentedon Mar 4, 2020
Thank you, I will try to reproduce and fix this issue ASAP
btacordex commentedon Mar 4, 2020
Actually, sorry, I just realized that phpMyAdmin didn't quite capture all the properties of the original table when I created the one-row copy. (Or it didn't copy them on export?) Please use this version:
MauricioFauth commentedon Mar 4, 2020
I was able to reproduce this on demo server. Works as expected with the MariaDB server.
williamdes commentedon Mar 11, 2020
@Pankaj-Wadhwani could you have a look ?
Pankaj-Wadhwani commentedon Mar 11, 2020
can you share screenshots?
williamdes commentedon Mar 11, 2020
MariaDB
MySQL 8
williamdes commentedon Mar 11, 2020
Disabling the OpenStreetMaps checkbox shows the data

Pankaj-Wadhwani commentedon Mar 21, 2020
I'm unable to find a solution , I will try to solve other issues. @williamdes
williamdes commentedon Apr 18, 2020
@asprazz Would you be interested to fix this issue ?
7 remaining items
williamdes commentedon Apr 19, 2020
"Incompatible Change: These functions now interpret latitude and longitude coordinates as in the order specified by the spatial reference system. The functions also accept an optional argument to override the default axis order."
https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-1.html
https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-1.html
"A new spatial function, ST_SwapXY(), accepts a geometry argument and swaps the X and Y values of each coordinate pair within the geometry. For more information, see Geometry Format Conversion Functions."
ankush-0x90 commentedon Apr 20, 2020
Yeah! It was introduced in MYSQL8.0.1, when they started using co-ordinates as latitude and longitude
This is the optional arugument that we can pass to ST_ASTEXT to override default axis order.
ST_TEXT(....., 'axis-order=long-lat')Should we go with this rather than ST_SwapXY ?
williamdes commentedon Apr 20, 2020
I think we could use this solution and also add a version restriction for this fix starting with 8.0.1
Merge #16088 - Fix #16012 - swapping long lat if mysql version >= 8.1
Add a ChangeLog entry for #16012
drtrppr commentedon Jun 10, 2020
Don't know if this is the right place to comment, but I'm trying to get some clear on flipflopping lat-lon I experience (see stackoverflow (as suggested on your homepage) https://stackoverflow.com/questions/62272155/what-to-expect-when-using-mariadb-phpmyadmin-when-working-with-datatype-geometr ) Don't get sattisfying response there, so I searched the phpmyadmin-issues. This issue comes close, exept it deals with mysql 8, I'm experiencing the flipflopping with mariadb 10.4.1.
williamdes commentedon Jun 10, 2020
Hi @drtrppr
Are you sure to reproduce the issue mentioned here with the data #16012 (comment) on MariaDB ?
drtrppr commentedon Jun 11, 2020
Thanks for response, and I'm absolutely NOT sure that I can reproduce the issue with data of comment :) . Things are getting fast beyond my level of knowlegde to be sure about the technical aspects, that's why I posted the question on Stackoverflow. My guess is that phpmyadmin/mariadb is working correctly, but I misunderstand how things work.
Main question at the moment is do lat-lon correspond to x-y in phpmyadmin (with a given SRID I guess)? If not, so lat-lon correspond to y-x by design, then there is no problem. I just have to swap values when importing data in database, and swap them again when exporting. It's just that it doesn't feel right.
Just want to be sure before importing a bunch of data, and having to swap them at some time etc.
If that's not the case, so lat-lon do correspond to x-y, I'll be happy to sent you all the details you want to have, if you're willing to help when I get stuck in the more technical details.
williamdes commentedon Jun 11, 2020
I think https://dba.stackexchange.com/a/182626/117444 is the answer.
I would say, do not adapt your data to phpMyAdmin this is a bad idea :)
Also I am considering adding a checkbox to invert the coordinates(very unsure)This did the trick to view the GIS data
drtrppr commentedon Jun 11, 2020
Ah, disagreement, ok, that makes difficult to code.
Reading what btacordex wrote to report the bug:
As phpmyadmin is targeted towards Mysql/Mariadb (homepage phpmyadmin), the lat-lon format should be the way to go?
But, what's puzzling me now, this issue is closed, so I assume phpmyadmin in combo with mysql 8 uses lat-lon now? I'm using mariadb 10.4 so I would expect the lat-lon format? So why still the invertion? There's something I'm not getting I think.
I was pleasantly surprised that these features showed up when using the GEOMETRY-format and really like using it. Makes it very easy to check geo-data. Indeed will not adapt data to phpMyAdmin, I think I will decide to use lat-lon, because of what btacordex wrote and my gpx-files also use the lat-lon format. So, that invertion-checkbox would be nice for the time being, but using the given SELECT-statement is my rescue-kit! Thanks.
williamdes commentedon Jun 11, 2020
"Incompatible Change: These functions now interpret latitude and longitude coordinates as in the order specified by the spatial reference system. The functions also accept an optional argument to override the default axis order." (#16012 (comment))
This issue is closed because we added a compatibility setting for newer MySQL versions (969f43c)
Yeah, I have a database that has no SRID and that maybe causes the inversion 🤔
I would need an expert to let us know if we are doing the lat long stuff right or not
Go the database way, and then use phpMyAdmin. If the results are incoherent will will have something to fix ;)
drtrppr commentedon Jun 12, 2020
I stumbled upon https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification :
Apparently order has a dependancy with units used. I'm using decimal degrees, so I need to use lon-lat order. When I use this order, phpadmin maps the data the way I expected.