Question

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 Quantum GIS (version 1.9) and saved it like 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 have any experience with this problem? Does anybody know how to switch order of coordinates (or axis) in geojson file? I have much more experience with xml based data formats than with json and because of that I hope that this isn't so silly question.

Was it helpful?

Solution

For anyone up there looking for the answer for the question in the title:

Coordinates order is longitude and latitude, or easting and northing.

Source:

3.1.1. Position

A position is the fundamental geometry construct. The "coordinates" member of a Geometry object is composed of either:

o one position in the case of a Point geometry,

o an array of positions in the case of a LineString or MultiPoint geometry,

o an array of LineString or linear ring (see Section 3.1.6) coordinates in the case of a Polygon or MultiLineString geometry, or

o an array of Polygon coordinates in the case of a MultiPolygon geometry.

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.

From GeoJSON specification

OTHER TIPS

You can use python to switch the coordinate order:

import json
import sys

geodata = json.loads(open(sys.argv[1]).read())
for obj in geodata:
    if "coordinates" in obj:
        # reorder from northing, easting to easting, northing
        northing = obj["coordinates"][0]
        easting = obj["coordinates"][1]
        obj["coordinates"] = [ easting, northing ]

print json.dumps(geodata)

run it like this:

python reorder_geojson.py geodata_ne.json > geodata_en.json
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top