Ticket #9448: layer_reference_ds.diff
File layer_reference_ds.diff, 2.8 KB (added by , 16 years ago) |
---|
-
django/contrib/gis/tests/test_gdal_ds.py
130 130 control_vals = source.field_values[fld_name][sl] 131 131 self.assertEqual(control_vals, test_vals) 132 132 133 def test03c_layer_references(self): 134 "Test to make sure Layer access is still available without the DataSource." 135 source = ds_list[0] 136 137 # See ticket #9448. 138 def get_layer(): 139 # This DataSource object is not accessible outside this 140 # scope. However, a reference should still be kept alive 141 # on the `Layer` returned. 142 ds = DataSource(source.ds) 143 return ds[0] 144 145 # Making sure we can call OGR routines on the Layer returned. 146 lyr = get_layer() 147 self.assertEqual(source.nfeat, len(lyr)) 148 self.assertEqual(source.gtype, lyr.geom_type.num) 149 133 150 def test04_features(self): 134 151 "Testing Data Source Features." 135 152 for source in ds_list: -
django/contrib/gis/gdal/datasource.py
111 111 l = get_layer(self._ptr, index) 112 112 else: 113 113 raise TypeError('Invalid index type: %s' % type(index)) 114 return Layer(l )114 return Layer(l, self) 115 115 116 116 def __len__(self): 117 117 "Returns the number of layers within the data source." -
django/contrib/gis/gdal/layer.py
25 25 "A class that wraps an OGR Layer, needs to be instantiated from a DataSource object." 26 26 27 27 #### Python 'magic' routines #### 28 def __init__(self, layer_ptr): 29 "Needs a C pointer (Python/ctypes integer) in order to initialize." 28 def __init__(self, layer_ptr, ds): 29 """ 30 Initializes on an OGR C pointer and the `DataSource` object that 31 owns this layer. The `DataSource` object is required so that 32 a reference to it is kept with this Layer. This prevents the 33 garbage collection of the `DataSource` while this `Layer` object 34 is still active. 35 """ 30 36 self._ptr = None # Initially NULL 31 37 if not layer_ptr: 32 38 raise OGRException('Cannot create Layer, invalid pointer given') 33 39 self._ptr = layer_ptr 40 self._ds = ds 34 41 self._ldefn = get_layer_defn(self._ptr) 35 42 # Does the Layer support random reading? 36 43 self._random_read = self.test_capability('RandomRead')