mirror of
https://github.com/django/django.git
synced 2025-06-02 10:09:12 +00:00
Made gis_terms be a set, rather than a dict with None for all keys.
This commit is contained in:
parent
6634cb7b53
commit
a53d7a0a50
@ -3,10 +3,12 @@ Base/mixin classes for the spatial backend database operations and the
|
|||||||
`SpatialRefSys` model the backend.
|
`SpatialRefSys` model the backend.
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.contrib.gis import gdal
|
from django.contrib.gis import gdal
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
|
|
||||||
class BaseSpatialOperations(object):
|
class BaseSpatialOperations(object):
|
||||||
"""
|
"""
|
||||||
This module holds the base `BaseSpatialBackend` object, which is
|
This module holds the base `BaseSpatialBackend` object, which is
|
||||||
@ -18,7 +20,7 @@ class BaseSpatialOperations(object):
|
|||||||
geometry_operators = {}
|
geometry_operators = {}
|
||||||
geography_operators = {}
|
geography_operators = {}
|
||||||
geography_functions = {}
|
geography_functions = {}
|
||||||
gis_terms = {}
|
gis_terms = set()
|
||||||
truncate_params = {}
|
truncate_params = {}
|
||||||
|
|
||||||
# Quick booleans for the type of this spatial backend, and
|
# Quick booleans for the type of this spatial backend, and
|
||||||
|
@ -3,7 +3,6 @@ from django.db.backends.mysql.base import DatabaseOperations
|
|||||||
from django.contrib.gis.db.backends.adapter import WKTAdapter
|
from django.contrib.gis.db.backends.adapter import WKTAdapter
|
||||||
from django.contrib.gis.db.backends.base import BaseSpatialOperations
|
from django.contrib.gis.db.backends.base import BaseSpatialOperations
|
||||||
|
|
||||||
from django.utils import six
|
|
||||||
|
|
||||||
class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
|
class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
|
|||||||
'within': 'MBRWithin',
|
'within': 'MBRWithin',
|
||||||
}
|
}
|
||||||
|
|
||||||
gis_terms = dict([(term, None) for term in list(geometry_functions) + ['isnull']])
|
gis_terms = set(geometry_functions) | set(['isnull'])
|
||||||
|
|
||||||
def geo_db_type(self, f):
|
def geo_db_type(self, f):
|
||||||
return f.geom_type
|
return f.geom_type
|
||||||
|
@ -18,6 +18,7 @@ from django.contrib.gis.geometry.backend import Geometry
|
|||||||
from django.contrib.gis.measure import Distance
|
from django.contrib.gis.measure import Distance
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
class SDOOperation(SpatialFunction):
|
class SDOOperation(SpatialFunction):
|
||||||
"Base class for SDO* Oracle operations."
|
"Base class for SDO* Oracle operations."
|
||||||
sql_template = "%(function)s(%(geo_col)s, %(geometry)s) %(operator)s '%(result)s'"
|
sql_template = "%(function)s(%(geo_col)s, %(geometry)s) %(operator)s '%(result)s'"
|
||||||
@ -32,6 +33,7 @@ class SDODistance(SpatialFunction):
|
|||||||
sql_template = ('%(function)s(%(geo_col)s, %(geometry)s, %(tolerance)s) '
|
sql_template = ('%(function)s(%(geo_col)s, %(geometry)s, %(tolerance)s) '
|
||||||
'%(operator)s %(result)s')
|
'%(operator)s %(result)s')
|
||||||
dist_func = 'SDO_GEOM.SDO_DISTANCE'
|
dist_func = 'SDO_GEOM.SDO_DISTANCE'
|
||||||
|
|
||||||
def __init__(self, op, tolerance=0.05):
|
def __init__(self, op, tolerance=0.05):
|
||||||
super(SDODistance, self).__init__(self.dist_func,
|
super(SDODistance, self).__init__(self.dist_func,
|
||||||
tolerance=tolerance,
|
tolerance=tolerance,
|
||||||
@ -40,6 +42,7 @@ class SDODistance(SpatialFunction):
|
|||||||
class SDODWithin(SpatialFunction):
|
class SDODWithin(SpatialFunction):
|
||||||
dwithin_func = 'SDO_WITHIN_DISTANCE'
|
dwithin_func = 'SDO_WITHIN_DISTANCE'
|
||||||
sql_template = "%(function)s(%(geo_col)s, %(geometry)s, %%s) = 'TRUE'"
|
sql_template = "%(function)s(%(geo_col)s, %(geometry)s, %%s) = 'TRUE'"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(SDODWithin, self).__init__(self.dwithin_func)
|
super(SDODWithin, self).__init__(self.dwithin_func)
|
||||||
|
|
||||||
@ -48,6 +51,7 @@ class SDOGeomRelate(SpatialFunction):
|
|||||||
relate_func = 'SDO_GEOM.RELATE'
|
relate_func = 'SDO_GEOM.RELATE'
|
||||||
sql_template = ("%(function)s(%(geo_col)s, '%(mask)s', %(geometry)s, "
|
sql_template = ("%(function)s(%(geo_col)s, '%(mask)s', %(geometry)s, "
|
||||||
"%(tolerance)s) %(operator)s '%(mask)s'")
|
"%(tolerance)s) %(operator)s '%(mask)s'")
|
||||||
|
|
||||||
def __init__(self, mask, tolerance=0.05):
|
def __init__(self, mask, tolerance=0.05):
|
||||||
# SDO_GEOM.RELATE(...) has a peculiar argument order: column, mask, geom, tolerance.
|
# SDO_GEOM.RELATE(...) has a peculiar argument order: column, mask, geom, tolerance.
|
||||||
# Moreover, the runction result is the mask (e.g., 'DISJOINT' instead of 'TRUE').
|
# Moreover, the runction result is the mask (e.g., 'DISJOINT' instead of 'TRUE').
|
||||||
@ -60,6 +64,7 @@ class SDORelate(SpatialFunction):
|
|||||||
mask_regex = re.compile(r'^(%s)(\+(%s))*$' % (masks, masks), re.I)
|
mask_regex = re.compile(r'^(%s)(\+(%s))*$' % (masks, masks), re.I)
|
||||||
sql_template = "%(function)s(%(geo_col)s, %(geometry)s, 'mask=%(mask)s') = 'TRUE'"
|
sql_template = "%(function)s(%(geo_col)s, %(geometry)s, 'mask=%(mask)s') = 'TRUE'"
|
||||||
relate_func = 'SDO_RELATE'
|
relate_func = 'SDO_RELATE'
|
||||||
|
|
||||||
def __init__(self, mask):
|
def __init__(self, mask):
|
||||||
if not self.mask_regex.match(mask):
|
if not self.mask_regex.match(mask):
|
||||||
raise ValueError('Invalid %s mask: "%s"' % (self.relate_func, mask))
|
raise ValueError('Invalid %s mask: "%s"' % (self.relate_func, mask))
|
||||||
@ -127,9 +132,8 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
|
|||||||
}
|
}
|
||||||
geometry_functions.update(distance_functions)
|
geometry_functions.update(distance_functions)
|
||||||
|
|
||||||
gis_terms = ['isnull']
|
gis_terms = set(['isnull'])
|
||||||
gis_terms += list(geometry_functions)
|
gis_terms.update(geometry_functions)
|
||||||
gis_terms = dict([(term, None) for term in gis_terms])
|
|
||||||
|
|
||||||
truncate_params = {'relate' : None}
|
truncate_params = {'relate' : None}
|
||||||
|
|
||||||
@ -272,7 +276,8 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
|
|||||||
given Aggregate instance.
|
given Aggregate instance.
|
||||||
"""
|
"""
|
||||||
agg_name = agg.__class__.__name__.lower()
|
agg_name = agg.__class__.__name__.lower()
|
||||||
if agg_name == 'union' : agg_name += 'agg'
|
if agg_name == 'union':
|
||||||
|
agg_name += 'agg'
|
||||||
if agg.is_extent:
|
if agg.is_extent:
|
||||||
sql_template = '%(function)s(%(field)s)'
|
sql_template = '%(function)s(%(field)s)'
|
||||||
else:
|
else:
|
||||||
|
@ -221,10 +221,9 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
|
|||||||
self.geometry = True
|
self.geometry = True
|
||||||
|
|
||||||
# Creating a dictionary lookup of all GIS terms for PostGIS.
|
# Creating a dictionary lookup of all GIS terms for PostGIS.
|
||||||
gis_terms = ['isnull']
|
self.gis_terms = set(['isnull'])
|
||||||
gis_terms += list(self.geometry_operators)
|
self.gis_terms.update(self.geometry_operators)
|
||||||
gis_terms += list(self.geometry_functions)
|
self.gis_terms.update(self.geometry_functions)
|
||||||
self.gis_terms = dict([(term, None) for term in gis_terms])
|
|
||||||
|
|
||||||
self.area = prefix + 'Area'
|
self.area = prefix + 'Area'
|
||||||
self.bounding_circle = BOUNDINGCIRCLE
|
self.bounding_circle = BOUNDINGCIRCLE
|
||||||
@ -565,7 +564,8 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
|
|||||||
if not self.check_aggregate_support(agg):
|
if not self.check_aggregate_support(agg):
|
||||||
raise NotImplementedError('%s spatial aggregate is not implmented for this backend.' % agg_name)
|
raise NotImplementedError('%s spatial aggregate is not implmented for this backend.' % agg_name)
|
||||||
agg_name = agg_name.lower()
|
agg_name = agg_name.lower()
|
||||||
if agg_name == 'union': agg_name += 'agg'
|
if agg_name == 'union':
|
||||||
|
agg_name += 'agg'
|
||||||
sql_template = '%(function)s(%(field)s)'
|
sql_template = '%(function)s(%(field)s)'
|
||||||
sql_function = getattr(self, agg_name)
|
sql_function = getattr(self, agg_name)
|
||||||
return sql_template, sql_function
|
return sql_template, sql_function
|
||||||
|
@ -117,9 +117,8 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
|
|||||||
super(DatabaseOperations, self).__init__(connection)
|
super(DatabaseOperations, self).__init__(connection)
|
||||||
|
|
||||||
# Creating the GIS terms dictionary.
|
# Creating the GIS terms dictionary.
|
||||||
gis_terms = ['isnull']
|
self.gis_terms = set(['isnull'])
|
||||||
gis_terms += self.geometry_functions.keys()
|
self.gis_terms.update(self.geometry_functions)
|
||||||
self.gis_terms = dict([(term, None) for term in gis_terms])
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def spatial_version(self):
|
def spatial_version(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user