Django

Code

Ticket #5433: remove_gdal_dep.patch

File remove_gdal_dep.patch, 1.8 kB (added by rcoup, 1 year ago)
  • django/contrib/gis/db/models/mixin.py

    old new  
    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 
    55 
     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 
     13 
    614# Until model subclassing is a possibility, a mixin class is used to add 
    715# the necessary functions that may be contributed for geographic objects. 
    816class GeoMixin: 
     
    1725 
    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): 
    2435        "Returns the spatial reference identifier (SRID) of the geometry." 
     
    2738 
    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): 
    3347        "Returns the WKT of the geometry."