[GIS] export to GeoJSON coordinates in the reverse order

geojsonqgis

This question has been asked before, but I don't understand how to use the answer given by cengel. I want to make a GeoJSON file with lat long coords, not the default of long lat coords. I have a current (wrong order) GeoJSON file, I have the original shp file it was created from and I can't for the life of me find a .gml that is referred to in the answer the first time this question was asked. Please Help! 🙁

Here is the old question:
Exporting GeoJSON file with correct order of coordinates?

Best Answer

There are couple of things which you might not know, which is causing all this issue.

Firstly the GeoJSON is supposed to have coordinates in longitude, latitude order. This can be seen in the specifications, which says:

The order of elements must follow x, y, z order (easting, northing, altitude for coordinates in a projected coordinate reference system, or longitude, latitude, altitude for coordinates in a geographic coordinate reference system).

Secondly, the Question which you have linked is actually about a different issue. That question deals with reading GML correctly, when it contains coordinates in latitude-longitude format. Hence the answers on it won't really help you.

Now coming to your issue. You need your data in a particular format. Looking at the code that you have posted, the geometry is expected in the following format:

-- polygon format: 
-- { 
--   ["name"] = polypoints = { { { lat, long }, { lat, long }, ... }, { { lat, long }, { lat, long }, ... } },
--   ["name"] = polypoints = { { { lat, long }, { lat, long }, ... }, { { lat, long }, { lat, long }, ... } },
-- }

If you look at this format, you'll see that even though this data looks like JSON, neither is it valid JSON, nor does it come even close to any formal GeoJSON.

Hence it really won't help you, even if we manage to produce GeoJSON with coordinates in latitude, longitude order.

So how do we solve your problem? Unfortunately, there isn't one easy solution. Some custom code will be required, or manual editing, none of which is really scales well.

You might best be served by getting the code re-written.