Ticket #5433: remove_gdal_dep.patch
File remove_gdal_dep.patch, 1.8 KB (added by , 17 years ago) |
---|
-
django/contrib/gis/db/models/mixin.py
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, SpatialReference5 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 13 6 14 # Until model subclassing is a possibility, a mixin class is used to add 7 15 # the necessary functions that may be contributed for geographic objects. 8 16 class GeoMixin: … … 17 25 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): 24 35 "Returns the spatial reference identifier (SRID) of the geometry." … … 27 38 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): 33 47 "Returns the WKT of the geometry."