Opened 12 years ago

Closed 12 years ago

#4754 closed defect (invalid)

GML driver read/write attribute mismatch

Reported by: ccrook Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords: gml
Cc:

Description

The version 1.9 gml driver seems to add an fid attribute to a gml encoded data.

This is demonstrated in the following python script which creates a test gml file without any attribute fields, then reopens it and checks the attribute count.

Version 1.8.0 output:

Gdal version: 1.8.0
Creating test.gml
Creation field count: 0
Reopening test.gml
Reopened field count: 0

Version 1.9.1 output:

Gdal version: 1.9.1
Creating test.gml
Creation field count: 0
Reopening test.gml
Reopened field count: 1
Field 0: fid

Script:

from osgeo import ogr, gdal

print 'Gdal version:',gdal.__version__

print "Creating test.gml"
drv = ogr.GetDriverByName('GML')
ds=drv.CreateDataSource('test.gml')
ly=ds.CreateLayer('test',None,ogr.wkbPoint)
dfn=ly.GetLayerDefn()
print "Creation field count:",dfn.GetFieldCount()
ft=ogr.Feature(ly.GetLayerDefn())
pt=ogr.Geometry(ogr.wkbPoint)
pt.SetPoint(0,10.0,20.0)
ft.SetGeometry(pt)
ly.CreateFeature(ft)
ds.Release()

print "Reopening test.gml"
ds=ogr.Open('test.gml')
ly=ds.GetLayer(0)
dfn=ly.GetLayerDefn()
print "Reopened field count:",dfn.GetFieldCount()
if dfn.GetFieldCount() > 0:
    print "Field 0:",dfn.GetFieldDefn(0).GetName()

Change History (4)

comment:1 by ccrook, 12 years ago

Component: defaultOGR_SF

comment:2 by Even Rouault, 12 years ago

Yes, this is a change that was made. It is necesserary to expose the fid because in some GML, the FID is a string or an integer than doesn't fit into 32 bits. See the "Feature id (fid / gml:id)" section of http://gdal.org/ogr/drv_gml.html

What's the problem with that ?

comment:3 by ccrook, 12 years ago

For me the problem is that the objects I write are not the same as the objects I read. This breaks a Quantum GIS plugin I maintain (MemoryLayerSaver), which writes out a set of attributes and expects to read back the same attributes.

However reading the link you sent it looks as if I can set GML_EXPOSE_FID to NO and fix this. I'll need to experiment with this.

comment:4 by Even Rouault, 12 years ago

Resolution: invalid
Status: newclosed

ok I'm closing this ticket based on the fact that the behaviour of the driver has some rational (hopefully ;-)), is documented, and can be tweaked to adopt behaviour of previous versions

Note: See TracTickets for help on using tickets.