Changeset 6188
- Timestamp:
- 09/14/07 09:02:38 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/db/models/mixin.py
r5661 r6188 1 # GEOS Routines2 1 from warnings import warn 2 3 # GEOS is a requirement 3 4 from django.contrib.gis.geos import GEOSGeometry 4 from django.contrib.gis.gdal import OGRGeometry, SpatialReference 5 6 # GDAL is a lot more complicated to install, and isn't necessary for many 7 # operations. 8 try: 9 from django.contrib.gis.gdal import OGRGeometry, SpatialReference 10 HAS_GDAL = True 11 except ImportError, e: 12 HAS_GDAL = False 5 13 6 14 # Until model subclassing is a possibility, a mixin class is used to add … … 18 26 def _get_GEOM_ogr(self, field, srid): 19 27 "Returns an OGR Python object for the geometry." 20 return OGRGeometry(getattr(self, field.attname).wkt, 21 SpatialReference('EPSG:%d' % srid)) 28 if HAS_GDAL: 29 return OGRGeometry(getattr(self, field.attname).wkt, 30 SpatialReference('EPSG:%d' % srid)) 31 else: 32 raise Exception, "GDAL is not installed!" 22 33 23 34 def _get_GEOM_srid(self, srid): … … 28 39 def _get_GEOM_srs(self, srid): 29 40 "Returns ane OGR Spatial Reference object of the geometry." 30 return SpatialReference('EPSG:%d' % srid) 41 if HAS_GDAL: 42 return SpatialReference('EPSG:%d' % srid) 43 else: 44 raise Exception, "GDAL is not installed!" 31 45 32 46 def _get_GEOM_wkt(self, field): … … 44 58 warn("use model.%s.area" % field.attname, DeprecationWarning) 45 59 return getattr(self, field.attname).area 46 47
