Django

Code

Changeset 6188

Show
Ignore:
Timestamp:
09/14/07 09:02:38 (1 year ago)
Author:
jbronn
Message:

gis: Fixed #5433 -- GDAL is not a prerequisite.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/db/models/mixin.py

    r5661 r6188  
    1 # GEOS Routines 
    21from warnings import warn 
     2 
     3# GEOS is a requirement 
    34from 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. 
     8try: 
     9    from django.contrib.gis.gdal import OGRGeometry, SpatialReference 
     10    HAS_GDAL = True 
     11except ImportError, e: 
     12    HAS_GDAL = False 
    513 
    614# Until model subclassing is a possibility, a mixin class is used to add 
     
    1826    def _get_GEOM_ogr(self, field, srid): 
    1927        "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!" 
    2233 
    2334    def _get_GEOM_srid(self, srid): 
     
    2839    def _get_GEOM_srs(self, srid): 
    2940        "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!" 
    3145 
    3246    def _get_GEOM_wkt(self, field): 
     
    4458        warn("use model.%s.area" % field.attname, DeprecationWarning) 
    4559        return getattr(self, field.attname).area 
    46  
    47