web/lib/django/contrib/gis/gdal/__init__.py
author ymh <ymh.work@gmail.com>
Wed, 02 Jun 2010 18:57:35 +0200
changeset 38 77b6da96e6f1
permissions -rw-r--r--
update django
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
"""
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
 This module houses ctypes interfaces for GDAL objects.  The following GDAL
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 objects are supported:
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 CoordTransform: Used for coordinate transformations from one spatial
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
  reference system to another.
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 Driver: Wraps an OGR data source driver.
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
  
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 DataSource: Wrapper for the OGR data source object, supports
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
  OGR-supported data sources.
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 Envelope: A ctypes structure for bounding boxes (GDAL library
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
  not required).
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 OGRGeometry: Object for accessing OGR Geometry functionality.
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 OGRGeomType: A class for representing the different OGR Geometry
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
  types (GDAL library not required).
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 SpatialReference: Represents OSR Spatial Reference objects.
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 The GDAL library will be imported from the system path using the default  
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 library name for the current OS. The default library path may be overridden
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
 by setting `GDAL_LIBRARY_PATH` in your settings with the path to the GDAL C 
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
 library on your system.  
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
 GDAL links to a large number of external libraries that consume RAM when 
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
 loaded.  Thus, it may desirable to disable GDAL on systems with limited
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
 RAM resources -- this may be accomplished by setting `GDAL_LIBRARY_PATH`
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
 to a non-existant file location (e.g., `GDAL_LIBRARY_PATH='/null/path'`; 
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
 setting to None/False/'' will not work as a string must be given).
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
"""
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
# Attempting to import objects that depend on the GDAL library.  The
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
# HAS_GDAL flag will be set to True if the library is present on
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
# the system.
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
try:
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    from django.contrib.gis.gdal.driver import Driver
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    from django.contrib.gis.gdal.datasource import DataSource
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    from django.contrib.gis.gdal.libgdal import gdal_version, gdal_full_version, gdal_release_date, GEOJSON, GDAL_VERSION
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    from django.contrib.gis.gdal.geometries import OGRGeometry
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    HAS_GDAL = True
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
except:
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
    HAS_GDAL, GEOJSON = False, False
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
try:
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
    from django.contrib.gis.gdal.envelope import Envelope
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
except ImportError:
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    # No ctypes, but don't raise an exception.
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    pass
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
from django.contrib.gis.gdal.error import check_err, OGRException, OGRIndexError, SRSException
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
from django.contrib.gis.gdal.geomtype import OGRGeomType