When converting to GeoJSON I’m finding that lat/lon are being transposed. I don’t understand the reason why and haven’t found any suitable answers in the MySQL documentation.
- The WKT seems to be correct as verified with https://wktmap.com/
- The GeoJSON is incorrect – it seems that lat/lon are transposed as verified with https://geojson.io/
- The column has the SRID set to
4326
- The GeoJSON is set to
EPSG:4326
too
I understand that GeoJSON should always be ordered lon-lat so does this suggest that I stored the data in MySQL with lon/lat transposed?
mysql> SHOW CREATE TABLE lookup_geometries G
*************************** 1. row ***************************
Table: lookup_geometries
Create Table: CREATE TABLE `lookup_geometries` (
`name` varchar(100) NOT NULL,
`geometry` geometry NOT NULL /*!80003 SRID 4326 */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.00 sec)
mysql> SELECT geometry, ST_asWKT(geometry), ST_asGeoJSON(geometry,4,2) FROM lookup_geometries WHERE name = "Newlands Corner" G
*************************** 1. row ***************************
geometry: 0xE6100000010100000000FCF8F0D19D4940759ABB4C0335E0BF
ST_asWKT(geometry): POINT(-0.5064713 51.2329694)
ST_asGeoJSON(geometry,4,2): {"crs": {"type": "name", "properties": {"name": "EPSG:4326"}}, "type": "Point", "coordinates": [51.233, -0.5065]}
1 row in set (0.00 sec)
2
Answers
A similar case was reported in 2020: https://bugs.mysql.com/bug.php?id=98731
It was closed as "not a bug" because:
Examples follow this response in the bug report (see the link above).
GeoJSON is always lon/lat as defined by the standard.