2009-12-22 23:18:51 +08:00
|
|
|
from django.db.backends.mysql.base import DatabaseOperations
|
|
|
|
|
|
|
|
from django.contrib.gis.db.backends.adapter import WKTAdapter
|
|
|
|
from django.contrib.gis.db.backends.base import BaseSpatialOperations
|
2014-05-23 03:51:30 +08:00
|
|
|
from django.contrib.gis.db.backends.utils import SpatialOperator
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2012-07-21 03:14:27 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
|
|
|
|
|
2014-08-12 20:08:40 +08:00
|
|
|
compiler_module = 'django.contrib.gis.db.models.sql.compiler'
|
2009-12-22 23:18:51 +08:00
|
|
|
mysql = True
|
|
|
|
name = 'mysql'
|
|
|
|
select = 'AsText(%s)'
|
|
|
|
from_wkb = 'GeomFromWKB'
|
|
|
|
from_text = 'GeomFromText'
|
|
|
|
|
|
|
|
Adapter = WKTAdapter
|
2013-11-03 05:02:56 +08:00
|
|
|
Adaptor = Adapter # Backwards-compatibility alias.
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2014-05-23 03:51:30 +08:00
|
|
|
gis_operators = {
|
|
|
|
'bbcontains': SpatialOperator(func='MBRContains'), # For consistency w/PostGIS API
|
|
|
|
'bboverlaps': SpatialOperator(func='MBROverlaps'), # .. ..
|
|
|
|
'contained': SpatialOperator(func='MBRWithin'), # .. ..
|
|
|
|
'contains': SpatialOperator(func='MBRContains'),
|
|
|
|
'disjoint': SpatialOperator(func='MBRDisjoint'),
|
|
|
|
'equals': SpatialOperator(func='MBREqual'),
|
|
|
|
'exact': SpatialOperator(func='MBREqual'),
|
|
|
|
'intersects': SpatialOperator(func='MBRIntersects'),
|
|
|
|
'overlaps': SpatialOperator(func='MBROverlaps'),
|
|
|
|
'same_as': SpatialOperator(func='MBREqual'),
|
|
|
|
'touches': SpatialOperator(func='MBRTouches'),
|
|
|
|
'within': SpatialOperator(func='MBRWithin'),
|
2013-05-09 23:13:13 +08:00
|
|
|
}
|
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def geo_db_type(self, f):
|
|
|
|
return f.geom_type
|
|
|
|
|
2014-05-23 03:51:30 +08:00
|
|
|
def get_geom_placeholder(self, f, value):
|
2009-12-22 23:18:51 +08:00
|
|
|
"""
|
|
|
|
The placeholder here has to include MySQL's WKT constructor. Because
|
|
|
|
MySQL does not support spatial transformations, there is no need to
|
|
|
|
modify the placeholder based on the contents of the given value.
|
|
|
|
"""
|
|
|
|
if hasattr(value, 'expression'):
|
2012-10-06 09:49:59 +08:00
|
|
|
placeholder = self.get_expression_column(value)
|
2009-12-22 23:18:51 +08:00
|
|
|
else:
|
|
|
|
placeholder = '%s(%%s)' % self.from_text
|
|
|
|
return placeholder
|