2

I want to integrate the GeoJSON of a shapefile into React.js to display it as an interactive map with OpenStreetMap used in the background as a tiled image.

I have used QGIS to export the shapefile polygons to GeoJSON format. When opening the GeoJSON file in a text editor the coordinates are arranged as longitude and latitude by default (see below example):

{
"type": "FeatureCollection",
"name": "AB_18_epsg4326",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [{ "type": "Feature", "properties": { "id": null, "BlockID": "18", "AreaName": "Alto Branco" }, "geometry": { "type": "MultiPolygon", 
        "coordinates": [ [ [ [ -35.883680840759709, -7.207758761892716 ], 
                     [ -35.882709722028402, -7.208009651845575 ], 
                     [ -35.882898093859403, -7.208733208791063 ], 
                     [ -35.883854465392915, -7.208480923455232 ], 
                     [ -35.883680840759709, -7.207758761892716 ] 
                ] ] ] } }
]
}

When integrating this to React.js and running the program - the polygon is visualised at the wrong place because the coordinates are supposed to be arranged as Latitude & Longitude in OSM instead of Longitude and Latitude.

Is there way to export this shapefile into GeoJSON with the default positions of the coordinates (i.e. longitude and latitude) changed to Latitude and Longitude using QGIS or R?

The desired export should be:

{
"type": "FeatureCollection",
"name": "AB_18_epsg4326",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [{ "type": "Feature", "properties": { "id": null, "BlockID": "18", "AreaName": "Alto Branco" }, "geometry": { "type": "MultiPolygon", 
        "coordinates": [ [ [ [  -7.207758761892716, -35.883680840759709 ], 
                     [  -7.208009651845575, -35.882709722028402 ], 
                     [  -7.208733208791063, -35.882898093859403 ], 
                     [  -7.208480923455232, -35.883854465392915 ], 
                     [  -7.207758761892716, -35.883680840759709 ] 
                ] ] ] } }
]
}
1
  • 1
    EPSG:4326 is lat long, so if the client isn't incorrect in expecting that order if the data is meant to be in that CRS. GeoJSON is not though in EPSG:4326
    – nmtoken
    Dec 16, 2019 at 8:26

1 Answer 1

6

The GeoJSON specification requires the coordinate order to be longitude, latitude. You should file a bug against your client.

A position is an array of numbers. There MUST be two or more elements. The first two elements are longitude and latitude, or easting and northing, precisely in that order and using decimal numbers. Altitude or elevation MAY be included as an optional third element.

Your Answer

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

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