I am receiving GML as part of a larger XML message. When I receive the XML it is unmarshalled to Java objects. I have no rights to alter the schemas or the generated Java code. Therefore, I later have to marshal the OpenGIS polygon back to XML. When I try to store it in the PostGIS database, I get the following exception:

org.postgresql.util.PSQLException: ERROR: unknown spatial reference system

This is my query:

INSERT INTO test (polygon) VALUES (ST_GeomFromGML('
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <ns1:Polygon srsName="http://metadata.ces.mil/mdr/ns/GSIP/crs/WGS84E_3D" ns1:id="P1" xmlns:ns6="http://www.isotc211.org/2005/gts" xmlns:ns5="http://release.niem.gov/niem/external/ogc/xls/1.1.0/dhs-gmo/2.1.0" xmlns:ns2="http://www.w3.org/1999/xlink" xmlns:ns1="http://www.opengis.net/gml/3.2" xmlns:ns4="http://www.isotc211.org/2005/gmd" xmlns:ns3="http://www.isotc211.org/2005/gco">
        <ns1:pos>32.23426 -110.34511 90.2</ns1:pos>
        <ns1:pos>32.23435 -110.34544 90.2</ns1:pos>
        <ns1:pos>32.23444 -110.34555 90.2</ns1:pos>
        <ns1:pos>32.23426 -110.34511 90.2</ns1:pos>
 </ns1:Polygon>', 4326))

If I try to remove the SRID from the query, I get the same exception. The column I try to store the polygon in, looks like this:

AddGeometryColumn('test', 'polygon', 4326, 'POLYGON', 3);

Any ideas? Please let me know if you need any more information.

  • A GML pos should just have an x and y, no? Looking at the docs, I see you can insert polyhedral surfaces, but you need to specify it like <gml:posList srsDimension="3">0 0 0 0 0 1 0 1 1 0 1 0 0 0 0</gml:posList>, ie, with a srsDimension. I accept that this might seem unlikely from the error message, but worth checking. Apr 28, 2016 at 10:12
  • If you have the GML unmarshalled already, you might want to consider using JTS and insert the geometries directly as spatial objects, and avoid the overhead of GML. Just a thought :D Apr 28, 2016 at 10:14
  • I tried adding srsDimension="3", but it didn't help. However, I found out that if I change the srsName to srsName="EPSG:4269" it works. I could override that attribute, but I will try to fix it otherwise first.
    – fossecode
    Apr 28, 2016 at 10:50
  • I am open to try alternative solutions. I briefly looked into JTS, and that is definitely an option. My current polygon object is a net.opengis.gml._3.PolygonType, do you have any idea on how I can convert it to a JTS polygon?
    – fossecode
    Apr 28, 2016 at 10:52
  • Something like: stackoverflow.com/questions/6570017/…. I don't know how to directly cast from one type to another, but if you have the coordinates, you can simply build the geometry from that. Apr 28, 2016 at 11:28

1 Answer 1


Explicitly set the correct srsName gmlPolygon.getValue().setSrsName("EPSG:4326");
I also had to add srsDimension to the points since they had x, y, z:
<ns1:pos srsDimension="3">32.23435 -110.34544 90.2</ns1:pos>

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.