I was testing rendering of data via GitHub in geojson format, because I wanted to use it for INSPIRE data. INSPIRE data are in GML 3.2.1 format. I've downloaded one of datasets from http://services.cuzk.cz/gml/inspire/cp/epsg-4258/ (which is in ETRS). I needed to get json file from it, so I've opened GML file in QGIS (version 1.9) and saved it as GeoJSON file (CRS=EPSG::4326) and then uploaded to my GitHub. Order of coordinates in geojson is (easting, northing), but after saving file from QGIS it's (northing, easting). My data comes from Czech Republic, but it's rendered in Yemen.

Does anybody know how to switch order of coordinates (or axis) in GeoJSON file?

  • Using QGIS 2, I cannot reproduce this error. The conversion to GeoJSON (EPSG 4326) works fine. I suggest upgrading to V2 (although I don't believe this problem existed in V1.9 either so it sounds like the software or solution which consumes the GeoJSON is wrong). Sep 30, 2013 at 16:32
  • There can't be any problem with solution, all I do is that I upload GeoJSON file to GitHub, which renders it only by opening it in GitHub filesystem.
    – Meďák
    Oct 6, 2013 at 17:19

2 Answers 2


Qgis uses the gdal libraries (in particular ogr) to perform the conversion. The ogr driver has limited support for GML. By default, the driver will swap the coordinates (details here). Using the command line and setting the parameter explicitly to not swap the coordinates might solve your problem.

ogr2ogr -f "GeoJSON" --config GML_INVERT_AXIS_ORDER_IF_LAT_LONG NO MyData.geojson MyData.gml

If your GML has multiple layers add the layer name like:

ogr2ogr -f "GeoJSON" --config GML_INVERT_AXIS_ORDER_IF_LAT_LONG NO MyData.geojson MyData.gml MyLayerName

If you are on Windows and don't have access to command line tools, you can install FWTools.

  • when I convert it your way, I have coordinates in proper order, but geojson file is not valid. I also found a way how to switch axis (which is enough for me), but it works only for .shp files.
    – Meďák
    Oct 8, 2013 at 10:38
  • @Meďák I suspect that the reason for an invalid geojson is that your .gml has several layers. The GeoJSON driver can only handle one layer at a time. You can find out if you have multiple layers with the command ogrinfo MyData.gml and tell ogr2ogr to only use one layer. I have updated my answer to reflect that possibility.
    – cengel
    Oct 8, 2013 at 16:29

In theory, to unswap the coordinates in QGIS you would go Settings → Options → System → (scroll down) Environment → (tick) Use custom variables

Then click on the + sign, and set

Apply        | Variable                          | Value

Then restart QGIS and hope for the best.

I say in theory because it's not working for me. However, it's not working from the command line using ogr2ogr either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.