Opened 12 years ago

Closed 11 years ago

#2493 closed defect (fixed)

GDAL thinks string field is an integer field in GML layer

Reported by: jbronn Owned by: chaitanya
Priority: normal Milestone:
Component: OGR_SF Version: 1.5.2
Severity: normal Keywords: gml
Cc: warmerdam

Description

The attached GML file has features that have three fields, 'dbl', 'int', and 'str' that are of real, integer, and string types, respectively. The 'str' field is reported as being of integer type instead of being string type.

>>> from osgeo import ogr
>>> ds = ogr.Open('test_point.gml')
>>> lyr = ds[0]
>>> ldefn = lyr.GetLayerDefn()
>>> [ldefn.GetFieldDefn(i).GetFieldTypeName(ldefn.GetFieldDefn(i).GetType()) for i in range(ldefn.GetFieldCount())]
['Real', 'Integer', 'Integer'] # Should be ['Real', 'Integer', 'String']

The GML file (and xsd) were generated from using ogr2ogr -F GML on an existing shapefile.

Attachments (6)

test_point.gml (2.2 KB) - added by jbronn 12 years ago.
test_point.xsd (2.0 KB) - added by jbronn 12 years ago.
parsexsd.cpp.diff (500 bytes) - added by chaitanya 11 years ago.
Fixes the problem with ignoring the .xsd file with 'type' attribute values with prefixes
ogr_gml_read.py.diff (1.2 KB) - added by chaitanya 11 years ago.
Added test for ticket#2493
test_point.2.gml (2.2 KB) - added by chaitanya 11 years ago.
Data file for the test to be added to 'autotest/ogr/data' folder
test_point.2.xsd (2.0 KB) - added by chaitanya 11 years ago.
Data file for the test to be added to 'autotest/ogr/data' folder

Download all attachments as: .zip

Change History (14)

Changed 12 years ago by jbronn

Attachment: test_point.gml added

Changed 12 years ago by jbronn

Attachment: test_point.xsd added

comment:1 Changed 11 years ago by warmerdam

Cc: warmerdam added
Component: defaultOGR_SF
Owner: changed from warmerdam to chaitanya

Chaitanya,

I *think* the GML driver will read the .xsd file if it is in the OGR produced "OGR simple features GML" format. Assuming that is true, could you look into whether we can exact the attribute field types from it in such a way that the field types are preserved with datasets like this?

We would need to add appropriate tests to the python test suite.

comment:2 Changed 11 years ago by chaitanya

The GMLReader::ParseXSD() method was not handling attribute values in the .xsd file that have a prefix. I am attaching a patch that ignores the prefix.

By the way, the attached test_point.xsd file has the second type listed as decimal(Real) and will be treated as such.

Frank, I have tried to handle the issue during type-name verification, but there are more such verifications further down the road. So, I am just skipping the prefix part right after extracting the 'type' attribute value.

Changed 11 years ago by chaitanya

Attachment: parsexsd.cpp.diff added

Fixes the problem with ignoring the .xsd file with 'type' attribute values with prefixes

comment:3 Changed 11 years ago by warmerdam

The patch looks fine, but now the hard part is to extend the GML test script to test this capability - presumably including some new (small) test data.

Changed 11 years ago by chaitanya

Attachment: ogr_gml_read.py.diff added

Added test for ticket#2493

Changed 11 years ago by chaitanya

Attachment: test_point.2.gml added

Data file for the test to be added to 'autotest/ogr/data' folder

Changed 11 years ago by chaitanya

Attachment: test_point.2.xsd added

Data file for the test to be added to 'autotest/ogr/data' folder

comment:4 Changed 11 years ago by chaitanya

Status: newassigned

Committed fix in trunk (r16644). Added test for the issue in trunk (r16641, r16642 and r16643).

Frank, Should I add this fix in the 1.5 branch too?

comment:5 Changed 11 years ago by Even Rouault

Chaintanya,

I've re-added ogr_gml_6 in r16645 that apparently got accidently removed in r16641

comment:6 Changed 11 years ago by warmerdam

Chaitanya,

Yes, please apply the update in the 1.6 and 1.5 branch. We do not normally port back the test suite additions - just the code change.

comment:7 Changed 11 years ago by chaitanya

Applied the fix in 1.5 (r16649) and 1.6 (r16650) branches.

comment:8 Changed 11 years ago by Even Rouault

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.