Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

gis: gdal: The feature and layer modules now uses OGRIndexError.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ea0ae54756d505b9280f379633cbfa2708ed7fce 1 parent 65b4cb2
@jbronn jbronn authored
14 django/contrib/gis/gdal/
@@ -4,7 +4,7 @@
# The GDAL C library, OGR exception, and the Field object
from django.contrib.gis.gdal.libgdal import lgdal
-from django.contrib.gis.gdal.error import OGRException
+from django.contrib.gis.gdal.error import OGRException, OGRIndexError
from django.contrib.gis.gdal.field import Field
from django.contrib.gis.gdal.geometries import OGRGeometry, OGRGeomType
@@ -35,11 +35,11 @@ def __getitem__(self, index):
i = self.index(index)
if index < 0 or index > self.num_fields:
- raise IndexError, 'index out of range'
+ raise OGRIndexError, 'index out of range'
i = index
return Field(lgdal.OGR_F_GetFieldDefnRef(self._feat, c_int(i)),
string_at(lgdal.OGR_F_GetFieldAsString(self._feat, c_int(i))))
def __iter__(self):
"Iterates over each field in the Feature."
for i in xrange(self.num_fields):
@@ -94,14 +94,18 @@ def geom_type(self):
#### Feature Methods ####
def get(self, field):
- "Returns the value of the field, instead of an instance of the Field object."
+ """
+ Returns the value of the field, instead of an instance of the Field
+ object. May take a string of the field name or a Field object as
+ parameters.
+ """
field_name = getattr(field, 'name', field)
return self.__getitem__(field_name).value
def index(self, field_name):
"Returns the index of the given field name."
i = lgdal.OGR_F_GetFieldIndex(self._feat, c_char_p(field_name))
- if i < 0: raise IndexError, 'invalid OFT field name given: "%s"' % field_name
+ if i < 0: raise OGRIndexError, 'invalid OFT field name given: "%s"' % field_name
return i
def clone(self):
4 django/contrib/gis/gdal/
@@ -8,7 +8,7 @@
from django.contrib.gis.gdal.envelope import Envelope, OGREnvelope
from django.contrib.gis.gdal.feature import Feature
from django.contrib.gis.gdal.geometries import OGRGeomType
-from django.contrib.gis.gdal.error import OGRException, check_err
+from django.contrib.gis.gdal.error import OGRException, OGRIndexError, check_err
from django.contrib.gis.gdal.srs import SpatialReference
# For more information, see the OGR C API source code:
@@ -48,7 +48,7 @@ def make_feature(offset):
if index < 0:
index = end - index
if index < 0 or index >= self.num_feat:
- raise IndexError, 'index out of range'
+ raise OGRIndexError, 'index out of range'
return make_feature(index)
# A slice was given
Please sign in to comment.
Something went wrong with that request. Please try again.