Opened 2 years ago

Closed 2 years ago

#6214 closed defect (fixed)

ExportToGML does not provide GML namespace declaration

Reported by: tomkralidis Owned by: hobu
Priority: normal Milestone: 2.1.0
Component: OGR_SF Version: unspecified
Severity: normal Keywords: gml namespace
Cc:

Description

(inspired by http://gis.stackexchange.com/questions/163826/in-python-how-to-encode-and-decode-complex-data-for-a-owslib-wps-call-to-pywps).

Example:

import xml.etree.ElementTree as etree
import ogr

geom_wkt = 'POINT (30 10)'
geom = ogr.CreateGeometryFromWkt( geom_wkt )

gml = geom.ExportToGML()

print(gml)

e = etree.fromstring(gml)

Yields:

<gml:Point><gml:coordinates>30,10</gml:coordinates></gml:Point>
Traceback (most recent call last):
  File "dd.py", line 12, in <module>
    e = etree.fromstring(gml)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1300, in XML
    parser.feed(text)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1642, in feed
    self._raiseerror(v)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: unbound prefix: line 1, column 0

This breaks XML parsers which expect namespace prefixes to be bound. So a result like:

<gml:Point xmlns:gml="http://www.opengis.net/gml"><gml:coordinates>30,10</gml:coordinates></gml:Point> would work (actual namespace TBD per the GML version[s] supported).

Change History (1)

comment:1 Changed 2 years ago by Even Rouault

Component: PythonBindingsOGR_SF
Milestone: 2.1.0
Resolution: fixed
Status: newclosed

Implemented per trunk r31431 "GML: add NAMESPACE_DECL=YES option to OGR_G_ExportToGMLEx() to add xmlns:gml=http://www.opengis.net/gml or http://www.opengis.net/gml/3.2 declaration; Also accept GML2 or GML32 as valid valiues for FORMAT option (#6214)"

See commit for how to use from Python. I didn't add the namespace declaration by default because it might cause very verbose output if the output is aggregated.

Note: See TracTickets for help on using tickets.