diff --git a/django/contrib/gis/gdal/feature.py b/django/contrib/gis/gdal/feature.py
index 47fd9e5..d08e786 100644
|
a
|
b
|
class Feature(GDALBase):
|
| 15 | 15 | "A class that wraps an OGR Feature, needs to be instantiated from a Layer object." |
| 16 | 16 | |
| 17 | 17 | #### Python 'magic' routines #### |
| 18 | | def __init__(self, feat, fdefn): |
| | 18 | def __init__(self, feat, fdefn, layer): |
| 19 | 19 | "Initializes on the pointers for the feature and the layer definition." |
| 20 | 20 | if not feat or not fdefn: |
| 21 | 21 | raise OGRException('Cannot create OGR Feature, invalid pointer given.') |
| 22 | 22 | self.ptr = feat |
| 23 | 23 | self._fdefn = fdefn |
| | 24 | self._layer = layer |
| 24 | 25 | |
| 25 | 26 | def __del__(self): |
| 26 | 27 | "Releases a reference to this object." |
| … |
… |
class Feature(GDALBase):
|
| 39 | 40 | if index < 0 or index > self.num_fields: |
| 40 | 41 | raise OGRIndexError('index out of range') |
| 41 | 42 | i = index |
| 42 | | return Field(self.ptr, i) |
| | 43 | return Field(self, i) |
| 43 | 44 | |
| 44 | 45 | def __iter__(self): |
| 45 | 46 | "Iterates over each field in the Feature." |
diff --git a/django/contrib/gis/gdal/field.py b/django/contrib/gis/gdal/field.py
index 12dc8b9..dc4d2b3 100644
|
a
|
b
|
class Field(GDALBase):
|
| 22 | 22 | self._index = index |
| 23 | 23 | |
| 24 | 24 | # Getting the pointer for this field. |
| 25 | | fld_ptr = capi.get_feat_field_defn(feat, index) |
| | 25 | fld_ptr = capi.get_feat_field_defn(feat.ptr, index) |
| 26 | 26 | if not fld_ptr: |
| 27 | 27 | raise OGRException('Cannot create OGR Field, invalid pointer given.') |
| 28 | 28 | self.ptr = fld_ptr |
| … |
… |
class Field(GDALBase):
|
| 42 | 42 | #### Field Methods #### |
| 43 | 43 | def as_double(self): |
| 44 | 44 | "Retrieves the Field's value as a double (float)." |
| 45 | | return capi.get_field_as_double(self._feat, self._index) |
| | 45 | return capi.get_field_as_double(self._feat.ptr, self._index) |
| 46 | 46 | |
| 47 | 47 | def as_int(self): |
| 48 | 48 | "Retrieves the Field's value as an integer." |
| 49 | | return capi.get_field_as_integer(self._feat, self._index) |
| | 49 | return capi.get_field_as_integer(self._feat.ptr, self._index) |
| 50 | 50 | |
| 51 | 51 | def as_string(self): |
| 52 | 52 | "Retrieves the Field's value as a string." |
| 53 | | return capi.get_field_as_string(self._feat, self._index) |
| | 53 | return capi.get_field_as_string(self._feat.ptr, self._index) |
| 54 | 54 | |
| 55 | 55 | def as_datetime(self): |
| 56 | 56 | "Retrieves the Field's value as a tuple of date & time components." |
| 57 | 57 | yy, mm, dd, hh, mn, ss, tz = [c_int() for i in range(7)] |
| 58 | | status = capi.get_field_as_datetime(self._feat, self._index, byref(yy), byref(mm), byref(dd), |
| | 58 | status = capi.get_field_as_datetime(self._feat.ptr, self._index, byref(yy), byref(mm), byref(dd), |
| 59 | 59 | byref(hh), byref(mn), byref(ss), byref(tz)) |
| 60 | 60 | if status: |
| 61 | 61 | return (yy, mm, dd, hh, mn, ss, tz) |
diff --git a/django/contrib/gis/gdal/layer.py b/django/contrib/gis/gdal/layer.py
index a2163bc..b2fef51 100644
|
a
|
b
|
class Layer(GDALBase):
|
| 57 | 57 | # ResetReading() must be called before iteration is to begin. |
| 58 | 58 | capi.reset_reading(self._ptr) |
| 59 | 59 | for i in xrange(self.num_feat): |
| 60 | | yield Feature(capi.get_next_feature(self._ptr), self._ldefn) |
| | 60 | yield Feature(capi.get_next_feature(self._ptr), self._ldefn, self) |
| 61 | 61 | |
| 62 | 62 | def __len__(self): |
| 63 | 63 | "The length is the number of features." |
| … |
… |
class Layer(GDALBase):
|
| 77 | 77 | if self._random_read: |
| 78 | 78 | # If the Layer supports random reading, return. |
| 79 | 79 | try: |
| 80 | | return Feature(capi.get_feature(self.ptr, feat_id), self._ldefn) |
| | 80 | return Feature(capi.get_feature(self.ptr, feat_id), self._ldefn, self) |
| 81 | 81 | except OGRException: |
| 82 | 82 | pass |
| 83 | 83 | else: |
diff --git a/django/contrib/gis/gdal/tests/test_ds.py b/django/contrib/gis/gdal/tests/test_ds.py
index 71d22a0..34f0399 100644
|
a
|
b
|
class DataSourceTest(unittest.TestCase):
|
| 141 | 141 | lyr = get_layer() |
| 142 | 142 | self.assertEqual(source.nfeat, len(lyr)) |
| 143 | 143 | self.assertEqual(source.gtype, lyr.geom_type.num) |
| | 144 | # Same issue for Feature/Field objects, see #18640 |
| | 145 | self.assertEqual(str(lyr[0]['str']), "1") |
| 144 | 146 | |
| 145 | 147 | def test04_features(self): |
| 146 | 148 | "Testing Data Source Features." |