Ticket #1442 (closed defect: fixed)
Feature.GetFieldAsInteger does not behave correctly on non existant field
| Reported by: | dpinte@… | Owned by: | rouault |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.7.0 |
| Component: | OGR_SF | Version: | 1.3.2 |
| Severity: | normal | Keywords: | |
| Cc: | warmerdam, hobu |
Description (last modified by mloskot) (diff)
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
Note: See
TracTickets for help on using
tickets.
