2

I've investigated the issue of coordinate order in GML and each time I think I've got it but I find my self confused once again.

I think some of my confusion may be to do with PostGIS. Doing a simple query on my database I can see the coordinates are stored correctly. The st_asgml function is outputting these coordinates in long,lat order which I think is correct for this srsName:

select title, ST_AsGML(3, locationgeometry, 15, 1), xmin(locationgeometry), ymin(locationgeometry) from tblobject where title='Chuska East Ridge';
-[ RECORD 1 ]-------------------------------------------------------------------------------
title    | Chuska East Ridge
st_asgml | <gml:Point srsName="urn:ogc:def:crs:EPSG::4326"><gml:pos srsDimension="2">-108.848780000000005 36.078707000000001</gml:pos></gml:Point>
xmin     | -108.84878
ymin     | 36.078707

However, if I take the same GML output above and run it through st_geomfromgml, the coordinates appear to have been reversed:

select xmin(st_geomfromgml('<gml:Point srsName="urn:ogc:def:crs:EPSG::4326"><gml:pos srsDimension="2">-108.848780000000005 36.078707000000001</gml:pos></gml:Point>'));
-[ RECORD 1 ]---
xmin | 36.078707

Am I missing something, or is this a bug in PostGIS? Can someone please confirm for me once and for all whether I should have lat,lon or lon,lat in GML when using the srsName urn:ogc:def:crs:EPSG::4326?

  • PostgreSQL version: 9.1.14
  • PostGIS version : POSTGIS="1.5.3" GEOS="3.2.2-CAPI-1.6.2" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.8" USE_STATS
  • 'xmin' and 'ymin' don't look like a postgis functions. Could you please explain what are they? Why don't you use 'ST_X' and 'ST_Y' instead? – Zia Dec 5 '14 at 22:23
  • Yeah sorry - some lazy typing here. You can substitute st_xmin and st_ymin or st_x and st_y but my point is the same. – PeteBrew Dec 12 '14 at 19:28
2

PostGIS typically expects coordinates in longitude-latitude or E-N order.

Looking at the second example from postgis.org/docs/ST_AsGML.html, it seems there is some flipping of coordinates:

-- Flip coordinates and output extended EPSG (16 | 1)--
SELECT ST_AsGML(3, ST_GeomFromText('POINT(5.23423 6.34535)',4326), 5, 17);
  st_asgml
  --------
<gml:Point srsName="urn:ogc:def:crs:EPSG::4326"><gml:pos>6.34535 5.23423</gml:pos></gml:Point>

And looking at an example in wiki/Geography_Markup_Language#Point_Profile, it seems GML does expect latitude-longitude or N-E ordering:

 <name>Lynn Valley</name>
 <description>A shot of the falls from the suspension bridge</description>
 <where>North Vancouver</where>
 <position>
     <gml:Point srsDimension="2" srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
         <gml:pos>49.40 -123.26</gml:pos>
     </gml:Point>
 </position>

So, expect some flipping coordinate confusion between GML and PostGIS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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