Changeset 6059
- Timestamp:
- 09/06/07 23:52:02 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/error.py
r5749 r6059 1 # OGR Error Codes 2 OGRERR_NONE = 0 3 OGRERR_NOT_ENOUGH_DATA = 1 4 OGRERR_NOT_ENOUGH_MEMORY = 2 5 OGRERR_UNSUPPORTED_GEOMETRY_TYPE = 3 6 OGRERR_UNSUPPORTED_OPERATION = 4 7 OGRERR_CORRUPT_DATA = 5 8 OGRERR_FAILURE = 6 9 OGRERR_UNSUPPORTED_SRS = 7 1 """ 2 This module houses the OGR & SRS Exception objects, and the 3 check_err() routine which checks the status code returned by 4 OGR methods. 5 """ 10 6 11 7 # OGR & SRS Exceptions … … 13 9 class SRSException(Exception): pass 14 10 15 def check_err(code, msg=False): 11 # OGR Error Codes 12 OGRERR_DICT = { 1 : (OGRException, 'Not enough data.'), 13 2 : (OGRException, 'Not enough memory.'), 14 3 : (OGRException, 'Unsupported geometry type.'), 15 4 : (OGRException, 'Unsupported operation.'), 16 5 : (OGRException, 'Corrupt data.'), 17 6 : (OGRException, 'OGR failure.'), 18 7 : (SRSException, 'Unsupported SRS.'), 19 } 20 OGRERR_NONE = 0 21 22 def check_err(code): 16 23 "Checks the given OGRERR, and raises an exception where appropriate." 17 24 18 25 if code == OGRERR_NONE: 19 26 return 20 elif code == OGRERR_NOT_ENOUGH_DATA: 21 raise OGRException, 'Not enough data!' 22 elif code == OGRERR_NOT_ENOUGH_MEMORY: 23 raise OGRException, 'Not enough memory!' 24 elif code == OGRERR_UNSUPPORTED_GEOMETRY_TYPE: 25 raise OGRException, 'Unsupported Geometry Type!' 26 elif code == OGRERR_UNSUPPORTED_OPERATION: 27 raise OGRException, 'Unsupported Operation!' 28 elif code == OGRERR_CORRUPT_DATA: 29 raise OGRException, 'Corrupt Data!' 30 elif code == OGRERR_FAILURE: 31 raise OGRException, 'OGR Failure!' 32 elif code == OGRERR_UNSUPPORTED_SRS: 33 raise SRSException, 'Unsupported SRS!' 27 elif code in OGRERR_DICT: 28 e, msg = OGRERR_DICT[code] 29 raise e, msg 34 30 else: 35 raise OGRException, 'Unknown error code: "%s"' % str(code)31 raise OGRException, 'Unknown error code: "%s"' % code django/branches/gis/django/contrib/gis/gdal/__init__.py
r5749 r6059 1 from d river import Driver2 from envelope import Envelope3 from d atasource import DataSource4 from srs import SpatialReference, CoordTransform5 from geometries import OGRGeometry6 from geomtype import OGRGeomType7 from error import check_err, OGRException, SRSException1 from django.contrib.gis.gdal.driver import Driver 2 from django.contrib.gis.gdal.envelope import Envelope 3 from django.contrib.gis.gdal.datasource import DataSource 4 from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform 5 from django.contrib.gis.gdal.geometries import OGRGeometry 6 from django.contrib.gis.gdal.geomtype import OGRGeomType 7 from django.contrib.gis.gdal.error import check_err, OGRException, SRSException 8 8 django/branches/gis/django/contrib/gis/gdal/layer.py
r5749 r6059 113 113 for i in xrange(self.num_fields) ] 114 114 115 #### Layer Methods #### 116 def get_fields(self, field_name): 117 """Returns a list containing the given field name for every Feature 118 in the Layer.""" 119 if not field_name in self.fields: 120 raise OGRException, 'invalid field name: %s' % field_name 121 return [feat.get(field_name) for feat in self] 122 123 def get_geoms(self, geos=False): 124 """Returns a list containing the OGRGeometry for every Feature in 125 the Layer.""" 126 if geos: 127 from django.contrib.gis.geos import fromstr 128 return [fromstr(feat.geom.wkt) for feat in self] 129 else: 130 return [feat.geom for feat in self]
