Changeset 5605
- Timestamp:
- 07/04/07 01:55:32 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/Field.py
r5586 r5605 49 49 def value(self): 50 50 "Returns an integer contained in this field." 51 return int(self._val) 51 try: 52 return int(self._val) 53 except ValueError: 54 return 0 52 55 53 56 class OFTIntegerList(Field): pass … … 56 59 def value(self): 57 60 "Returns a float contained in this field." 58 return float(self._val) 61 62 try: 63 return float(self._val) 64 except ValueError: 65 #FIXME: 0? None? 66 return 0 67 68 59 69 60 70 class OFTRealList(Field): pass django/branches/gis/django/contrib/gis/gdal/Layer.py
r5587 r5605 36 36 def __getitem__(self, index): 37 37 "Gets the Feature at the specified index." 38 if index < 0 or index >= self.num_feat: 39 raise IndexError, 'index out of range' 40 return Feature(lgdal.OGR_L_GetFeature(self._layer, c_long(index))) 38 def make_feature(offset): 39 return Feature(lgdal.OGR_L_GetFeature(self._layer, 40 c_long(offset))) 41 end = self.num_feat 42 if not isinstance(index, (slice, int)): 43 raise TypeError 44 if isinstance(index,int): 45 if index < 0: 46 index = end - index 47 if index < 0 or index >= self.num_feat: 48 raise IndexError, 'index out of range' 49 yield make_feature(index) 50 else: #isinstance(index,slice) 51 start, stop, stride = index.indices(end) 52 for offset in xrange(start,stop,stride): 53 yield make_feature(offset) 41 54 42 55 def __iter__(self): 43 56 "Iterates over each Feature in the Layer." 44 45 # Resetting the Layer before beginning iteration 46 lgdal.OGR_L_ResetReading(self._layer) 47 48 # Incrementing over each feature in the layer, and yielding 49 # to the caller of the function. 50 for i in xrange(self.num_feat): 51 yield self.__getitem__(i) 57 return self.__getitem__(slice(self.num_feat)) 52 58 53 59 def __len__(self): django/branches/gis/django/contrib/gis/tests/test_gdal_ds.py
r5587 r5605 66 66 67 67 # Incrementing through each layer, this tests __iter__ 68 for layer in ds: 68 for layer in ds: 69 69 # Making sure we get the number of features we expect 70 70 self.assertEqual(len(layer), source.nfeat) 71 72 layer[0] #can index 73 layer[:1] #can slice 71 74 72 75 # Making sure we get the number of fields we expect … … 95 98 for feat in layer: 96 99 # Making sure the number of fields is what's expected. 97 self.assertEqual(source.nfld, len( feat))100 self.assertEqual(source.nfld, len(list(feat))) 98 101 self.assertEqual(source.gtype, feat.geom_type) 99 102
