Opened 12 years ago

Last modified 7 years ago

#1990 new enhancement

Automatically swap X/Y coordinates in GML using urn: srs syntax

Reported by: xificurk Owned by: pramsey
Priority: medium Milestone: PostGIS Fund Me
Component: postgis Version: 2.0.x
Keywords: Cc:

Description

ST_AsGML always outputs coordinates in order X,Y.

⇒ SELECT st_asgml(st_setsrid(st_makepoint(15, 50), 4326), 15, 0);

<gml:Point srsName="EPSG:4326"><gml:coordinates>15,50</gml:coordinates></gml:Point>

⇒ SELECT st_asgml(st_setsrid(st_makepoint(15, 50), 4326), 15, 1);

<gml:Point srsName="urn:ogc:def:crs:EPSG::4326"><gml:coordinates>15,50</gml:coordinates></gml:Point>

⇒ SELECT st_asgml(st_setsrid(st_makepoint(15, 50), 4326), 15, 16);

<gml:Point srsName="EPSG:4326"><gml:coordinates>15,50</gml:coordinates></gml:Point>

On the other hand, ST_GeomFromGML swaps coordinates, if given srsName in format like 'urn:ogc:def:crs:EPSG::4326' instead of simple 'EPSG:4326'. Although the examples use 4326 SRS, it does not depend on this exact setting.

⇒ SELECT st_astext(st_geomfromgml('<gml:Point xmlns:gml="http://www.opengis.net/gml/3.2" srsName="urn:ogc:def:crs:EPSG::4326"><gml:coordinates>15,50</gml:coordinates></gml:Point>'));

POINT(50 15)

ruian⇒ SELECT st_astext(st_geomfromgml('<gml:Point xmlns:gml="http://www.opengis.net/gml/3.2" srsName="EPSG:4326"><gml:coordinates>15,50</gml:coordinates></gml:Point>'));

POINT(15 50)

Tested on 64bit Gentoo setup with fresh postgis install on top of PostgreSQL 9.1.5. POSTGIS="2.0.1 r9979" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.8.0, 6 March 2012" LIBXML="2.8.0"

Change History (6)

comment:1 by strk, 12 years ago

You need to add 16 to the st_asgml options to get the swap. Indeed I'm not sure why GeomFromGML swaps based on presence of the "url" prefix.

Is is a GML prescription that "urn"-prefixed srsName imply a lat/long order ?

comment:2 by pramsey, 12 years ago

Yes, that's exactly what the guidance from OGC is: urn-formed srsNames should obey the "new order of things", epsg formed srsNames can do whatever you like (gah!)

comment:3 by pramsey, 12 years ago

Milestone: PostGIS 2.0.2PostGIS Future
Summary: Inconsistent X/Y coordinates swapping in GMLAutomatically swap X/Y coordinates in GML using urn: srs syntax
Type: defectenhancement

I think auto-swapping constitutes a new feature, since the desired behaviour here is already available if the correct parameter is provided.

comment:4 by xificurk, 12 years ago

Well, the first point was that the option 16 (at least on my build) does not swap the coordinates. The second point was that PostGIS swaps the coordinates when reading GML with urn-formed srsName, but NOT when writing (option 1) GML with urn-formed srsName.

comment:5 by pramsey, 12 years ago

The doco says the 16 option is only useful for GML3 output, and I did find I had to request GML3 in order to see the behaviour, but see it I did:

select st_asgml(3, 'SRID=4326;POINT(10 20)'::geometry,8,16);

I think this still qualifies as an enhancement request, not a defect.

comment:6 by robe, 7 years ago

Milestone: PostGIS FuturePostGIS Fund Me

Milestone renamed

Note: See TracTickets for help on using tickets.