app/django/contrib/gis/gdal/__init__.py
changeset 323 ff1a9aa48cfd
equal deleted inserted replaced
322:6641e941ef1e 323:ff1a9aa48cfd
       
     1 """
       
     2  This module houses ctypes interfaces for GDAL objects.  The following GDAL
       
     3  objects are supported:
       
     4 
       
     5  CoordTransform: Used for coordinate transformations from one spatial
       
     6   reference system to another.
       
     7 
       
     8  Driver: Wraps an OGR data source driver.
       
     9   
       
    10  DataSource: Wrapper for the OGR data source object, supports
       
    11   OGR-supported data sources.
       
    12 
       
    13  Envelope: A ctypes structure for bounding boxes (GDAL library
       
    14   not required).
       
    15 
       
    16  OGRGeometry: Layer for accessing OGR Geometry objects.
       
    17 
       
    18  OGRGeomType: A class for representing the different OGR Geometry
       
    19   types (GDAL library not required).
       
    20 
       
    21  SpatialReference: Represents OSR Spatial Reference objects.
       
    22 
       
    23  The GDAL library will be imported from the system path using the default  
       
    24  library name for the current OS. The default library path may be overridden
       
    25  by setting `GDAL_LIBRARY_PATH` in your settings with the path to the GDAL C 
       
    26  library on your system.  
       
    27 
       
    28  GDAL links to a large number of external libraries that consume RAM when 
       
    29  loaded.  Thus, it may desirable to disable GDAL on systems with limited
       
    30  RAM resources -- this may be accomplished by setting `GDAL_LIBRARY_PATH`
       
    31  to a non-existant file location (e.g., `GDAL_LIBRARY_PATH='/null/path'`; 
       
    32  setting to None/False/'' will not work as a string must be given).
       
    33 """
       
    34 import sys
       
    35 
       
    36 # Attempting to import objects that depend on the GDAL library.  The
       
    37 # HAS_GDAL flag will be set to True if the library is present on
       
    38 # the system.
       
    39 try:
       
    40     from django.contrib.gis.gdal.driver import Driver
       
    41     from django.contrib.gis.gdal.datasource import DataSource
       
    42     from django.contrib.gis.gdal.libgdal import gdal_version, gdal_full_version, gdal_release_date
       
    43     from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
       
    44     from django.contrib.gis.gdal.geometries import OGRGeometry, GEOJSON
       
    45     HAS_GDAL = True
       
    46 except:
       
    47     HAS_GDAL, GEOJSON = False, False
       
    48 
       
    49 # The envelope, error, and geomtype modules do not actually require the
       
    50 # GDAL library, but still nead at least Python 2.4 and ctypes.
       
    51 PYTHON23 = sys.version_info[0] == 2 and sys.version_info[1] == 3
       
    52 if not PYTHON23:
       
    53     try:
       
    54         from django.contrib.gis.gdal.envelope import Envelope
       
    55         from django.contrib.gis.gdal.error import check_err, OGRException, OGRIndexError, SRSException
       
    56         from django.contrib.gis.gdal.geomtype import OGRGeomType
       
    57     except ImportError:
       
    58         # No ctypes, but don't raise an exception.
       
    59         pass