Opened 10 years ago

Closed 10 years ago

#3683 closed defect (fixed)

OGR produces invalid GML element name for a OGRGeometryCollection object

Reported by: Even Rouault Owned by: Even Rouault
Priority: normal Milestone: 1.7.3
Component: OGR_SF Version: unspecified
Severity: normal Keywords: GML multigeometry geometrycollection
Cc: warmerdam, crschmidt

Description (last modified by Even Rouault)

OGR currently writes <gml:GeometryCollection>, but this is not and has never been valid GML 2... The right element is <gml:MultiGeometry>. See

The error is also confirmed because PostGis? got it right :

ogrinfo PG:dbname=autotest -sql "select AsGML(GeomFromText('GEOMETRYCOLLECTION (POINT(0 1))'))"

So it's time to fix things on the write side and validate against the GML schemas. I'll make the reading part tolerant to both old invalid syntax and new valid syntax.

I'll probably backport only the fix for the reading part in 1.7 branch, but not the fix for the writing part

Change History (2)

comment:1 Changed 10 years ago by Even Rouault

Description: modified (diff)

comment:2 Changed 10 years ago by Even Rouault

Resolution: fixed
Status: newclosed
  • r20057 /trunk/gdal/ogr/ (3 files in 2 dirs): GML : Write valid <gml:MultiGeometry> element instead of the non-conformant <gml:GeometryCollection>. For backward compatibility, recognize both syntax for the reading part (#3683)
  • r20058 /trunk/autotest/ogr/ Expected result is <gml:MultiGeometry> now (#3683)
  • r20059 /branches/1.7/gdal/ogr/ (gml2ogrgeometry.cpp ogrsf_frmts/gml/gmlhandler.cpp): GML geometry reading: accept <gml:MultiGeometry> as valid, which is the official GML way of expressing a geometrycollection, and will be used by OGR >= 1.8.0. Still produce - and recognize - the old non-conformant <gml:GeometryCollection> to avoid breaking depending applications that would rely on that (#3683)

The following script now produces out.gml and out.xsd that validate with "xmllint -schema out.xsd out.gml"

import ogr
ds = ogr.GetDriverByName('GML').CreateDataSource('out.gml')
import osr
sr = osr.SpatialReference()
lyr = ds.CreateLayer('layer', srs = sr, geom_type = ogr.wkbGeometryCollection)
feature_defn = lyr.GetLayerDefn()
feat = ogr.Feature(feature_defn)
geom = ogr.CreateGeometryFromWkt('GEOMETRYCOLLECTION (POINT(0 1))')
ds = None

Note: See TracTickets for help on using tickets.