Django

Code

Show
Ignore:
Timestamp:
02/10/08 20:25:01 (10 months ago)
Author:
jbronn
Message:

gis: Fixed 6414, and applied DRY to spatial backend internals. Changes include:

(1) Support for distance calculations on geometry fields with geodetic coordinate systems (e.g., WGS84, the default).
(2) The get_db_prep_save and get_db_prep_lookup have been moved from the spatial backends to common implementations in GeometryField.
(3) Simplified SQL construction for GeoQuerySet methods.
(4) SpatialBackend now contains all spatial backend dependent settings.

Files:

Legend:

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

    r6919 r7104  
    1 class GeoFieldSQL(object): 
     1from types import UnicodeType 
     2 
     3def gqn(val): 
    24    """ 
    3     Container for passing values to `parse_lookup` from the various 
    4     backend geometry fields. 
     5    The geographic quote name function; used for quoting tables and  
     6    geometries (they use single rather than the double quotes of the 
     7    backend quotename function). 
    58    """ 
    6     def __init__(self, where=[], params=[]): 
    7         self.where = where 
    8         self.params = params 
    9  
    10     def __str__(self): 
    11         return self.as_sql() 
    12  
    13     def as_sql(self, quote=False): 
    14         if not quote: 
    15             return self.where[0] % tuple(self.params) 
    16         else: 
    17             # Used for quoting WKT on certain backends. 
    18             tmp_params = ["'%s'" % self.params[0]] 
    19             tmp_params.extend(self.params[1:]) 
    20             return self.where[0] % tuple(tmp_params) 
     9    if isinstance(val, basestring): 
     10        if isinstance(val, UnicodeType): val = val.encode('ascii') 
     11        return "'%s'" % val 
     12    else: 
     13        return str(val) 
    2114 
    2215class SpatialOperation(object):