mirror of
https://github.com/django/django.git
synced 2025-10-25 06:36:07 +00:00
Improved messages in IndexErrors raised by GDAL objects.
This commit is contained in:
@@ -89,12 +89,12 @@ class DataSource(GDALBase):
|
||||
if isinstance(index, str):
|
||||
layer = capi.get_layer_by_name(self.ptr, force_bytes(index))
|
||||
if not layer:
|
||||
raise IndexError('invalid OGR Layer name given: "%s"' % index)
|
||||
raise IndexError('Invalid OGR layer name given: %s.' % index)
|
||||
elif isinstance(index, int):
|
||||
if 0 <= index < self.layer_count:
|
||||
layer = capi.get_layer(self._ptr, index)
|
||||
else:
|
||||
raise IndexError('index out of range')
|
||||
raise IndexError('Index out of range when accessing layers in a datasource: %s.' % index)
|
||||
else:
|
||||
raise TypeError('Invalid index type: %s' % type(index))
|
||||
return Layer(layer, self)
|
||||
|
||||
@@ -38,7 +38,7 @@ class Feature(GDALBase):
|
||||
elif 0 <= index < self.num_fields:
|
||||
i = index
|
||||
else:
|
||||
raise IndexError('index out of range')
|
||||
raise IndexError('Index out of range when accessing field in a feature: %s.' % index)
|
||||
return Field(self, i)
|
||||
|
||||
def __len__(self):
|
||||
@@ -111,5 +111,5 @@ class Feature(GDALBase):
|
||||
"Return the index of the given field name."
|
||||
i = capi.get_field_index(self.ptr, force_bytes(field_name))
|
||||
if i < 0:
|
||||
raise IndexError('invalid OFT field name given: "%s"' % field_name)
|
||||
raise IndexError('Invalid OFT field name given: %s.' % field_name)
|
||||
return i
|
||||
|
||||
@@ -564,7 +564,7 @@ class LineString(OGRGeometry):
|
||||
elif dim == 3:
|
||||
return (x.value, y.value, z.value)
|
||||
else:
|
||||
raise IndexError('index out of range: %s' % index)
|
||||
raise IndexError('Index out of range when accessing points of a line string: %s.' % index)
|
||||
|
||||
def __len__(self):
|
||||
"Return the number of points in the LineString."
|
||||
@@ -616,7 +616,7 @@ class Polygon(OGRGeometry):
|
||||
if 0 <= index < self.geom_count:
|
||||
return OGRGeometry(capi.clone_geom(capi.get_geom_ref(self.ptr, index)), self.srs)
|
||||
else:
|
||||
raise IndexError('index out of range: %s' % index)
|
||||
raise IndexError('Index out of range when accessing rings of a polygon: %s.' % index)
|
||||
|
||||
# Polygon Properties
|
||||
@property
|
||||
@@ -655,7 +655,7 @@ class GeometryCollection(OGRGeometry):
|
||||
if 0 <= index < self.geom_count:
|
||||
return OGRGeometry(capi.clone_geom(capi.get_geom_ref(self.ptr, index)), self.srs)
|
||||
else:
|
||||
raise IndexError('index out of range: %s' % index)
|
||||
raise IndexError('Index out of range when accessing geometry in a collection: %s.' % index)
|
||||
|
||||
def __len__(self):
|
||||
"Return the number of geometries in this Geometry Collection."
|
||||
|
||||
Reference in New Issue
Block a user