When using ogr2ogr to convert a polygon from a .shp file to GeoJSON, I noticed that it writes the coordinates in order lat, long. I noticed this because whenever I tried to view the GeoJSON on a map, it would place the polygon in the middle of nowhere; I then read a bit more about GeoJSON and realized that the format requires the (x,y,z) order (long,lat,altitude) [source]. Is there a way for me to specify that ogr2ogr should write the GeoJSON in that order? Or is there any other way for me to get around this problem?

I'm 100% open to the possibility that I'm misunderstanding GeoJSON and that it doesn't actually have to be in long,lat,altitude order.

1 Answer 1


Looks like ogr2ogr has support for exactly this problem.

The below is copied directly from that page:

How do I flip coordinates when they are not in the expected order

The EPSG has a recommanded order for geographic SRS where the coordinates tuples of a geometry must appear in the (latitude, longitude) order, whereas most GIS will properly display such geometries if they appear in the (longitude, latitude) order. This issue can be often encountered in situation with GML3 files, WFS 1.1 data, etc... that adhere to the (latitude, longitude) order.

When, for some reason, the coordinate order isn't the one that is wished, the following trick can be used to flip them:

ogr2ogr -s_srs "+proj=latlong +datum=WGS84 +axis=neu +wktext"
        -t_srs "+proj=latlong +datum=WGS84 +axis=enu +wktext" dest.shp source.shp

... An alternative way of achieving the same result, providing using GDAL 2.0 compiled with Spatialite support to benefit from SQLite SQL dialect, is:

ogr2ogr -dialect SQLite -sql "SELECT SwapCoordinates(geometry) AS geometry, * FROM source" dest.shp source.shp
  • Only the alternative way is working. Changing the axis from neu to enu change the output of Data axis to CRS axis mapping: 2,1 to Data axis to CRS axis mapping: 1,2. However, in QGIS, the axis change seems to be ignored and there is not swap.
    – ThomasG77
    Commented Dec 14, 2021 at 20:30

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.