Opened 17 years ago

Last modified 15 years ago

#1442 closed defect

Feature.GetFieldAsInteger does not behave correctly on non existant field — at Version 3

Reported by: dpinte@… Owned by: Mateusz Łoskot
Priority: normal Milestone: 1.7.0
Component: OGR_SF Version: 1.3.2
Severity: normal Keywords:
Cc: warmerdam, hobu

Description (last modified by warmerdam)

Using Feature.GetFieldAsInteger on a inexistant field in the feature, answer is always 0. I guess it should report a ValueError like Feature.GetField (or even an AttributeError).

Demonstration : 

did@geru-itae:~/Documents/ucl/alert/python$ python
Python 2.4.4 (#2, Jan 13 2007, 17:50:26)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ogr
>>> dataset = ogr.Open('alert/test/scenario1/polygones.shp')
>>> layer = dataset.GetLayer()
>>> feature = layer.GetNextFeature()
>>> print "Test with an existing field"
Test with an existing field
>>> feature.GetFieldIndex('cat')
0
>>> feature.GetFieldAsInteger(feature.GetFieldIndex('cat'))
1
>>> print "Test with a non existant field"
Test with a non existant field
>>> feature.GetFieldIndex('id')
-1
>>> feature.GetFieldAsInteger(feature.GetFieldIndex('id'))
0
>>> feature.GetField(feature.GetFieldIndex('id'))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/ogr.py", line 854, in GetField
    return _gdal.OGR_F_GetField( self._o, fld_index )
ValueError: Illegal field requested in GetField().

Change History (1)

comment:3 by warmerdam, 17 years ago

Cc: warmerdam added
Description: modified (diff)
Milestone: 1.4.2
Owner: changed from warmerdam to Mateusz Łoskot
Priority: highestnormal

Mateusz,

Chat with me about what you think the solution should be before implementing it for this.

Note: See TracTickets for help on using tickets.