1

I'm currently running Postgres 9.1 with PostGIS 2.0.

I am trying to create a polygon geometry from the following GML:

<gml:Surface gml:id="ID_63_1413425013514_23322" srsName="urn:ogc:def:crs:EPSG::4326">
<gml:patches>
    <gml:PolygonPatch>
        <gml:exterior>
            <gml:LinearRing>
                <gml:pos>51.018333435058594 14.270000457763672</gml:pos>
                <gml:pos>51.016666412353516 14.399999618530273</gml:pos>
                <gml:pos>51.003334045410156 14.566666603088379</gml:pos>
                <gml:pos>50.95805740356445 14.574999809265137</gml:pos>
                <gml:pos>50.90277862548828 14.38611125946045</gml:pos>
                <gml:pos>50.9183349609375 14.398333549499512</gml:pos>
                <gml:pos>50.94166564941406 14.396666526794434</gml:pos>
                <gml:pos>50.95000076293945 14.300000190734863</gml:pos>
                <gml:pos>51.018333435058594 14.270000457763672</gml:pos>
            </gml:LinearRing>
        </gml:exterior>
    </gml:PolygonPatch>
</gml:patches>
</gml:Surface>

So I run the following command:

INSERT INTO test (polygon) VALUES ( (SELECT ST_GeomFromGML( 'gml') ) )

This executes correctly and produces a geometry in the table. However when I come to view the geometry in Quantum GIS there is clearly a problem and when I retrieve the GML through PostGIS I get the following:

SELECT ST_AsGML( polygon ) from test where id=1;

<gml:Polygon srsName="EPSG:4326">
<gml:outerBoundaryIs>
    <gml:LinearRing>
        <gml:coordinates>
            14.270000457763672,51.018333435058594
            14.399999618530273,51.016666412353516
            14.566666603088379,51.003334045410156
            14.574999809265137,50.958057403564453
            14.386111259460449,50.902778625488281
            14.398333549499512,50.9183349609375
            14.396666526794434,50.941665649414062
            14.300000190734863,50.950000762939453
            14.270000457763672,51.018333435058594
            14.399999618530273,51.016666412353516
            14.566666603088379,51.003334045410156
            14.574999809265137,50.958057403564453
            14.386111259460449,50.902778625488281
            14.398333549499512,50.9183349609375
            14.396666526794434,50.941665649414062
            14.300000190734863,50.950000762939453
            14.270000457763672,51.018333435058594
            14.566666603088379,51.003334045410156
            14.574999809265137,50.958057403564453
            14.386111259460449,50.902778625488281
            14.398333549499512,50.9183349609375
            14.396666526794434,50.941665649414062
            14.300000190734863,50.950000762939453
            14.270000457763672,51.018333435058594
            14.574999809265137,50.958057403564453
            14.386111259460449,50.902778625488281
            14.398333549499512,50.9183349609375
            14.396666526794434,50.941665649414062
            14.300000190734863,50.950000762939453
            14.270000457763672,51.018333435058594
            14.386111259460449,50.902778625488281
            14.398333549499512,50.9183349609375
            14.396666526794434,50.941665649414062
            14.300000190734863,50.950000762939453
            14.270000457763672,51.018333435058594
            14.398333549499512,50.9183349609375
            14.396666526794434,50.941665649414062
            14.300000190734863,50.950000762939453
            14.270000457763672,51.018333435058594
            14.396666526794434,50.941665649414062
            14.300000190734863,50.950000762939453
            14.270000457763672,51.018333435058594
            14.300000190734863,50.950000762939453
            14.270000457763672,51.018333435058594
            14.270000457763672,51.018333435058594
        </gml:coordinates>
    </gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>

I am slightly concerned that the Lat/long points have been reversed in the output but at the moment my main problem is that the nine original points are repeated and with each repeat one point is removed causing the rendering of the geometry to be useless and causing it to be useless for any further calculations.

Can someone please give me an idea of what I'm doing wrong.

  • Looks like multiple sets of test data - are you sure the table was empty before you inserted? – Kieveli Mar 17 '15 at 12:32
  • I've tried with it empty and each time I'm inserting a new row so that shouldn't be causing the problem I don't think... – Dan Mar 17 '15 at 13:23
0

I can repeat your issue with your GML. It seems that PostGIS does not like it. I can't say if there is something wrong in the GML or bug in PostGIS or just missing support for that GML version but I could insert a similar geometry as follows:

CREATE TABLE gml_test (id integer, geometry geometry);

Insert geometry as GML3:

insert into gml_test values(4, st_geomfromgml('
<gml:Polygon  srsName="urn:ogc:def:crs:EPSG::4326">
<gml:exterior>
<gml:LinearRing>
<gml:posList srsDimension="2">51.018333435058594 14.270000457763672 51.016666412353516 14.399999618530273 51.003334045410156 14.566666603088379 50.958057403564453 14.574999809265137 50.902778625488281 14.386111259460449 50.9183349609375 14.398333549499512 50.941665649414062 14.396666526794434 50.950000762939453 14.300000190734863 51.018333435058594 14.270000457763672
</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>'));

The coordinate order is OK. PostGIS is using internally longitude-latitude order but it knows that "urn:ogc:def:crs:EPSG::4326" that was used in input means that coordinates are presented in latitude-longitude.

Where did you get your GML? If it is valid I would suggest to ask why it does not behave well from postgis-users mailing list.

0

After upgrading to postgres 9.4 and PostGIS 2.1 the problem is resolved. Having searched around the PostGIS tickets it looks as if this was the original problem and was fixed in 2.1.4.

http://trac.osgeo.org/postgis/ticket/2704#comment:2

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.