[Geojson] coordinate order
Christopher Schmidt
crschmidt at metacarta.com
Mon Mar 10 13:29:45 PDT 2008
On Mon, Mar 10, 2008 at 03:55:58PM -0400, Norman Vine wrote:
> Tim Schaub writes:
> > Sean Gillies wrote:
> > > Tim Schaub wrote:
> > >>
> > >>
> > >> Regarding the order of elements in the coordinates array for GeoJSON
> > >> geometries, we say that the first two elements are in x, y order (lon,
> > >> lat for dd). This is what we have said from the start.
> > >>
> > >> The change to the spec is to accommodate CRS that define a different
> > >> coordinate order. Instead of requiring all clients to know about all
> > >> CRS coordinate order conventions, we require that GeoJSON geometries
> > >> referencing a CRS that defines non-xy coordinate order include a
> > >> "coordinate_order" member in the CRS object.
> > >>
> > >> This means a point geometry that references EPSG:4326
> > would look like this:
> > >>
> > >> {
> > >> "type": "Point",
> > >> "coordinates": [-180.0, 90.0],
> > >> "crs": {
> > >> "type": "EPSG",
> > >> "properties": {"code": 4326},
> > >> "coordinate_order": [1, 0]
> > >> }
> > >> }
> > >>
> > >
>
> I thought we meant that if the coordinate order was different then X,Y
> then even if crs was present that one must supply "coordinate_order"
>
> So proper access to the coordinate array coords[] for 'simple clients'
> could still be done eg.
>
> for point in coords:
> x = point[coordinate_order[1]]
> y = point[coordinate_order[0]]
No.
"For type "Point", each element in the coordinates array is a number
representing the point coordinate in one dimension. The order of
elements follows x, y order (or longitude, latitude for coordinates in
decimal degrees)."
x = point['coordinates'][0]
y = point['coordinates'][1]
Always. No questions. No alternatives.
> Note that for clients that know the CRS this might simplify to
>
> for point in coords:
> lat = point[0]
> lon = point[1]
>
> As this is implied by the CRS
No. For clients that know the CRS, they can do:
point[crs['axis'][0]] = points[coordinate_order[0]]
point[crs['axis'][1]] = points[coordinate_order[1]]
By default, we assume
crs['axis'] = ['x', 'y']
And therefore
coordinate_order = [0, 1]
Leads to:
point['x'] = points[0]
point['y'] = points[1]
If, instead,
crs['axis'] = ["y","x"]
then you must explicitly state:
coordinate_order = [1, 0]
So that:
point[crs['axis'][0]] = points[coordinate_order[0]]
point[crs['axis'][1]] = points[coordinate_order[1]]
remains true.
The benefit is that if:
crs['axis'] = ["x", "y", "z"]
you can do:
coordinate_order = [0, 1, 2]
And then:
point[crs['axis'][0]] = points[coordinate_order[0]]
point[crs['axis'][1]] = points[coordinate_order[1]]
point[crs['axis'][2]] = points[coordinate_order[2]]
Or, more generally:
for axis in range(len(axis)):
point[crs['axis'][axis]] = points[coordinate_order[axis]]
And you can know what your point['x'], point['y'], point['z'] are, based
on your understanding of the CRS.
EPSG has definitions like:
<axis>
<CoordinateSystemAxis gml:id="epsg-axis-39"
gml:uom="urn:x-ogc:def:uom:EPSG:9001">
<axisAbbrev>Y</axisAbbrev>
<axisDirection codeSpace="EPSG">east</axisDirection>
</CoordinateSystemAxis>
</axis>
<axis>
<CoordinateSystemAxis gml:id="epsg-axis-40"
gml:uom="urn:x-ogc:def:uom:EPSG:9001">
<axisAbbrev>X</axisAbbrev>
<axisDirection codeSpace="EPSG">north</axisDirection>
</CoordinateSystemAxis>
</axis>
In this case, you would have, in your knowledge of the CRS:
crs['axis'] = ['Y', 'X']
and you would have, in your data:
coordinate_order = [1, 0]
Because crs['axis'][coordinate_order[0]] = "X" is true, which matches to
what the spec tells you *must* be true -- that X is first, and Y is
second.
Regards,
--
Christopher Schmidt
MetaCarta
More information about the GeoJSON
mailing list