summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/contrib/gis/gdal/__init__.py14
-rw-r--r--django/contrib/gis/gdal/error.py48
-rw-r--r--django/contrib/gis/gdal/layer.py16
3 files changed, 45 insertions, 33 deletions
diff --git a/django/contrib/gis/gdal/__init__.py b/django/contrib/gis/gdal/__init__.py
index 255f781ddb..d47c66fc20 100644
--- a/django/contrib/gis/gdal/__init__.py
+++ b/django/contrib/gis/gdal/__init__.py
@@ -1,8 +1,8 @@
-from driver import Driver
-from envelope import Envelope
-from datasource import DataSource
-from srs import SpatialReference, CoordTransform
-from geometries import OGRGeometry
-from geomtype import OGRGeomType
-from error import check_err, OGRException, SRSException
+from django.contrib.gis.gdal.driver import Driver
+from django.contrib.gis.gdal.envelope import Envelope
+from django.contrib.gis.gdal.datasource import DataSource
+from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
+from django.contrib.gis.gdal.geometries import OGRGeometry
+from django.contrib.gis.gdal.geomtype import OGRGeomType
+from django.contrib.gis.gdal.error import check_err, OGRException, SRSException
diff --git a/django/contrib/gis/gdal/error.py b/django/contrib/gis/gdal/error.py
index 7162e2eb18..439b2b993d 100644
--- a/django/contrib/gis/gdal/error.py
+++ b/django/contrib/gis/gdal/error.py
@@ -1,35 +1,31 @@
-# OGR Error Codes
-OGRERR_NONE = 0
-OGRERR_NOT_ENOUGH_DATA = 1
-OGRERR_NOT_ENOUGH_MEMORY = 2
-OGRERR_UNSUPPORTED_GEOMETRY_TYPE = 3
-OGRERR_UNSUPPORTED_OPERATION = 4
-OGRERR_CORRUPT_DATA = 5
-OGRERR_FAILURE = 6
-OGRERR_UNSUPPORTED_SRS = 7
+"""
+ This module houses the OGR & SRS Exception objects, and the
+ check_err() routine which checks the status code returned by
+ OGR methods.
+"""
# OGR & SRS Exceptions
class OGRException(Exception): pass
class SRSException(Exception): pass
-def check_err(code, msg=False):
- "Checks the given OGRERR, and raises an exception where appropriate."
+# OGR Error Codes
+OGRERR_DICT = { 1 : (OGRException, 'Not enough data.'),
+ 2 : (OGRException, 'Not enough memory.'),
+ 3 : (OGRException, 'Unsupported geometry type.'),
+ 4 : (OGRException, 'Unsupported operation.'),
+ 5 : (OGRException, 'Corrupt data.'),
+ 6 : (OGRException, 'OGR failure.'),
+ 7 : (SRSException, 'Unsupported SRS.'),
+ }
+OGRERR_NONE = 0
+def check_err(code):
+ "Checks the given OGRERR, and raises an exception where appropriate."
+
if code == OGRERR_NONE:
return
- elif code == OGRERR_NOT_ENOUGH_DATA:
- raise OGRException, 'Not enough data!'
- elif code == OGRERR_NOT_ENOUGH_MEMORY:
- raise OGRException, 'Not enough memory!'
- elif code == OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
- raise OGRException, 'Unsupported Geometry Type!'
- elif code == OGRERR_UNSUPPORTED_OPERATION:
- raise OGRException, 'Unsupported Operation!'
- elif code == OGRERR_CORRUPT_DATA:
- raise OGRException, 'Corrupt Data!'
- elif code == OGRERR_FAILURE:
- raise OGRException, 'OGR Failure!'
- elif code == OGRERR_UNSUPPORTED_SRS:
- raise SRSException, 'Unsupported SRS!'
+ elif code in OGRERR_DICT:
+ e, msg = OGRERR_DICT[code]
+ raise e, msg
else:
- raise OGRException, 'Unknown error code: "%s"' % str(code)
+ raise OGRException, 'Unknown error code: "%s"' % code
diff --git a/django/contrib/gis/gdal/layer.py b/django/contrib/gis/gdal/layer.py
index 1d343ef363..f11adc5a8f 100644
--- a/django/contrib/gis/gdal/layer.py
+++ b/django/contrib/gis/gdal/layer.py
@@ -112,3 +112,19 @@ class Layer(object):
return [ string_at(lgdal.OGR_Fld_GetNameRef(lgdal.OGR_FD_GetFieldDefn(self._ldefn, i)))
for i in xrange(self.num_fields) ]
+ #### Layer Methods ####
+ def get_fields(self, field_name):
+ """Returns a list containing the given field name for every Feature
+ in the Layer."""
+ if not field_name in self.fields:
+ raise OGRException, 'invalid field name: %s' % field_name
+ return [feat.get(field_name) for feat in self]
+
+ def get_geoms(self, geos=False):
+ """Returns a list containing the OGRGeometry for every Feature in
+ the Layer."""
+ if geos:
+ from django.contrib.gis.geos import fromstr
+ return [fromstr(feat.geom.wkt) for feat in self]
+ else:
+ return [feat.geom for feat in self]