August 04, 2005

Coordinates in GML

Coordinates in GML can be a little confusing to the newbie.  This is mostly because GML has more than one way of writing them.  In many of the examples on this page coordinates are expressed using the gml:coordinates property tag.

For example:

 <gml:Point gml:id="p21" srsName="urn:ogc:def:crs:EPSG:6.6:4326">
    <gml:coordinates>45.67, 88.56</gml:coordinates>
 </gml:Point>

Note that when we express coordinates in this way, the individual coordinates like 88.56 are not visible in the XML - the whole text content of the <gml:coordinates> element is just one string.  To make the coordinates visible in GML, GML 3. introduced the <gml:pos> element and then the <gml:posList> element.  {GML already had the <gml:coord> element - however this should be treated as a defect and NEVER used}.  Using the <gml:pos> element the above example is written:

 <gml:Point gml:id="p21" srsName="urn:ogc:def:crs:EPSG:6.6:4326">
    <gml:pos dimension="2">45.67 88.56</gml:pos>
 </gml:Point>

The posList element is used for list of coordinate tuples such as for linear geometries. A <gml:LineString> using the <gml:coordinates> property would be written:

 <gml:LineString gml:id="p21" srsName="urn:ogc:def:crs:EPSG:6.6:4326">
    <gml:coordinates>45.67, 88.56 55.56,89.44</gml:coordinates>
 </gml:LineString >

Using the <gml:posList> element this would be written as:

 <gml:LineString gml:id="p21" srsName="urn:ogc:def:crs:EPSG:6.6:4326">
    <gml:posList dimension="2">45.67 88.56 55.56 89.44</gml:posList>
 </gml:LineString >

'''How do I know which to use?'''

In the future use only <gml:pos> or <gml:posList>. 

Since many current GML data servers (WFS) and conversion tools may only support <gml:coordinates>, however, this will quickly change the next several months.  If you are creating data - use <gml:pos> or <gml:posList>.  If you are writing GML processing software it is a good idea to also support <gml:coordinates>.  Support for <gml:coord> is not necessary.

To understand the use of the srsName attribute see the Wikipedia article on GML and Coordinate Systems.

Posted by RLake at 01:33:41 | Permanent Link | Comments (1) |
Comments
1 - Hi, thanks for the informative blog.

For the srsName attribute, the article on Wikipedia states:

The OGC has developed a URN structure and a set specific URNs to encode some common Coordinate Reference Systems.

Cannot seem to find this list of "common" CRSs, or any guide as to what they might represent. What srsName would I use, for example, to say "decimal degrees, with N,E = "-", and S,W = "+"?

Sorry if I'm missing something obvious, as a newcomer to GML with a very simple need - to represent closed polygons of geographic areas, with decimal degrees specifying the vertices.

Any pointers would be most appreciated. (Comment this)

Written by: Ron Lake at 2008/02/05 - 10:54:51
Write a comment