Django

Code

Show
Ignore:
Timestamp:
06/15/08 14:48:57 (5 months ago)
Author:
jbronn
Message:

gis: Refactor of the GeoQuerySet; new features include:

(1) Creation of internal API that eases generation of GeoQuerySet methods.
(2) GeoQuerySet.distance now returns Distance objects instead of floats.
(3) Added the new GeoQuerySet methods: area, centroid, difference, envelope, intersection, length, make_line, mem_size, num_geom, num_points, perimeter, point_on_surface, scale, svg, sym_difference, translate, union.
(4) The model_att keyword may be used to customize the attribute that GeoQuerySet methods attach output to.
(5) Geographic distance lookups and GeoQuerySet.distance calls now use ST_distance_sphere by default (performance benefits far outweigh small loss in accuracy); ST_distance_spheroid may still be used by specifying an option.
(6) GeoQuerySet methods may now operate accross ForeignKey? relations specified via the field_name keyword (but this does not work on Oracle).
(7) Area now has the same units of measure as Distance.

Backward Incompatibilites:

  • The aggregate union method is now known as unionagg.
  • The field_name keyword used for GeoQuerySet methods may no longer be specified via positional arguments.
  • Distance objects returned instead of floats from GeoQuerySet.distance.
  • ST_Distance_sphere used by default for geographic distance calculations.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/db/backend/__init__.py

    r7512 r7641  
    44 Specifically, this module will import the correct routines and modules 
    55 needed for GeoDjango to interface with the spatial database. 
    6   
    7  Some of the more important classes and routines from the spatial backend 
    8  include: 
    9  
    10  (1) `GeoBackEndField`, a base class needed for GeometryField. 
    11  (2) `get_geo_where_clause`, a routine used by `GeoWhereNode`. 
    12  (3) `GIS_TERMS`, a listing of all valid GeoDjango lookup types. 
    13  (4) `SpatialBackend`, a container object for information specific to the 
    14      spatial backend. 
    156""" 
    167from django.conf import settings 
    17 from django.db.models.sql.query import QUERY_TERMS 
    188from django.contrib.gis.db.backend.util import gqn 
    19  
    20 # These routines (needed by GeoManager), default to False. 
    21 ASGML, ASKML, DISTANCE, DISTANCE_SPHEROID, EXTENT, TRANSFORM, UNION, VERSION = tuple(False for i in range(8)) 
    22  
    23 # Lookup types in which the rest of the parameters are not 
    24 # needed to be substitute in the WHERE SQL (e.g., the 'relate' 
    25 # operation on Oracle does not need the mask substituted back 
    26 # into the query SQL.). 
    27 LIMITED_WHERE = [] 
    289 
    2910# Retrieving the necessary settings from the backend. 
    3011if settings.DATABASE_ENGINE == 'postgresql_psycopg2': 
    31     from django.contrib.gis.db.backend.postgis.adaptor import \ 
    32         PostGISAdaptor as GeoAdaptor 
    33     from django.contrib.gis.db.backend.postgis.field import \ 
    34         PostGISField as GeoBackendField 
    35     from django.contrib.gis.db.backend.postgis.creation import create_spatial_db 
    36     from django.contrib.gis.db.backend.postgis.query import \ 
    37         get_geo_where_clause, POSTGIS_TERMS as GIS_TERMS, \ 
    38         ASGML, ASKML, DISTANCE, DISTANCE_SPHEROID, DISTANCE_FUNCTIONS, \ 
    39         EXTENT, GEOM_SELECT, TRANSFORM, UNION, \ 
    40         MAJOR_VERSION, MINOR_VERSION1, MINOR_VERSION2 
    41     # PostGIS version info is needed to determine calling order of some 
    42     # stored procedures (e.g., AsGML()). 
    43     VERSION = (MAJOR_VERSION, MINOR_VERSION1, MINOR_VERSION2) 
    44     SPATIAL_BACKEND = 'postgis' 
     12    from django.contrib.gis.db.backend.postgis import create_spatial_db, get_geo_where_clause, SpatialBackend 
    4513elif settings.DATABASE_ENGINE == 'oracle': 
    46     from django.contrib.gis.db.backend.adaptor import WKTAdaptor as GeoAdaptor 
    47     from django.contrib.gis.db.backend.oracle.field import \ 
    48         OracleSpatialField as GeoBackendField 
    49     from django.contrib.gis.db.backend.oracle.creation import create_spatial_db 
    50     from django.contrib.gis.db.backend.oracle.query import \ 
    51         get_geo_where_clause, ORACLE_SPATIAL_TERMS as GIS_TERMS, \ 
    52         ASGML, DISTANCE, DISTANCE_FUNCTIONS, GEOM_SELECT, TRANSFORM, UNION 
    53     SPATIAL_BACKEND = 'oracle' 
    54     LIMITED_WHERE = ['relate'] 
     14    from django.contrib.gis.db.backend.oracle import create_spatial_db, get_geo_where_clause, SpatialBackend 
    5515elif settings.DATABASE_ENGINE == 'mysql': 
    56     from django.contrib.gis.db.backend.adaptor import WKTAdaptor as GeoAdaptor 
    57     from django.contrib.gis.db.backend.mysql.field import \ 
    58         MySQLGeoField as GeoBackendField 
    59     from django.contrib.gis.db.backend.mysql.creation import create_spatial_db 
    60     from django.contrib.gis.db.backend.mysql.query import \ 
    61         get_geo_where_clause, MYSQL_GIS_TERMS as GIS_TERMS, GEOM_SELECT 
    62     DISTANCE_FUNCTIONS = {} 
    63     SPATIAL_BACKEND = 'mysql' 
     16    from django.contrib.gis.db.backend.mysql import create_spatial_db, get_geo_where_clause, SpatialBackend 
    6417else: 
    6518    raise NotImplementedError('No Geographic Backend exists for %s' % settings.DATABASE_ENGINE) 
    66  
    67 class SpatialBackend(object): 
    68     "A container for properties of the SpatialBackend." 
    69     # Stored procedure names used by the `GeoManager`. 
    70     as_kml = ASKML 
    71     as_gml = ASGML 
    72     distance = DISTANCE 
    73     distance_spheroid = DISTANCE_SPHEROID 
    74     extent = EXTENT 
    75     name = SPATIAL_BACKEND 
    76     select = GEOM_SELECT 
    77     transform = TRANSFORM 
    78     union = UNION 
    79      
    80     # Version information, if defined. 
    81     version = VERSION 
    82      
    83     # All valid GIS lookup terms, and distance functions. 
    84     gis_terms = GIS_TERMS 
    85     distance_functions = DISTANCE_FUNCTIONS 
    86      
    87     # Lookup types where additional WHERE parameters are excluded. 
    88     limited_where = LIMITED_WHERE 
    89  
    90     # Shortcut booleans. 
    91     mysql = SPATIAL_BACKEND == 'mysql' 
    92     oracle = SPATIAL_BACKEND == 'oracle' 
    93     postgis = SPATIAL_BACKEND == 'postgis' 
    94  
    95     # Class for the backend field. 
    96     Field = GeoBackendField 
    97  
    98     # Adaptor class used for quoting GEOS geometries in the database. 
    99     Adaptor = GeoAdaptor