Django

Code

root/django/branches/gis/django/contrib/gis/db/backend/mysql/field.py

Revision 7104, 1.9 kB (checked in by jbronn, 10 months ago)

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.

Line 
1 from django.db import connection
2 from django.db.models.fields import Field # Django base Field class
3 from django.contrib.gis.db.backend.mysql.query import GEOM_FROM_TEXT
4
5 # Quotename & geographic quotename, respectively.
6 qn = connection.ops.quote_name
7
8 class MySQLGeoField(Field):
9     """
10     The backend-specific geographic field for MySQL.
11     """
12
13     def _geom_index(self, style, db_table):
14         """
15         Creates a spatial index for the geometry column.  If MyISAM tables are
16         used an R-Tree index is created, otherwise a B-Tree index is created.
17         Thus, for best spatial performance, you should use MyISAM tables
18         (which do not support transactions).  For more information, see Ch.
19         16.6.1 of the MySQL 5.0 documentation.
20         """
21
22         # Getting the index name.
23         idx_name = '%s_%s_id' % (db_table, self.column)
24        
25         sql = style.SQL_KEYWORD('CREATE SPATIAL INDEX ') + \
26               style.SQL_TABLE(qn(idx_name)) + \
27               style.SQL_KEYWORD(' ON ') + \
28               style.SQL_TABLE(qn(db_table)) + '(' + \
29               style.SQL_FIELD(qn(self.column)) + ');'
30         return sql
31
32     def _post_create_sql(self, style, db_table):
33         """
34         Returns SQL that will be executed after the model has been
35         created.
36         """
37         # Getting the geometric index for this Geometry column.
38         if self._index:
39             return (self._geom_index(style, db_table),)
40         else:
41             return ()
42
43     def db_type(self):
44         "The OpenGIS name is returned for the MySQL database column type."
45         return self._geom
46
47     def get_placeholder(self, value):
48         """
49         The placeholder here has to include MySQL's WKT constructor.  Because
50         MySQL does not support spatial transformations, there is no need to
51         modify the placeholder based on the contents of the given value.
52         """
53         return '%s(%%s)' % GEOM_FROM_TEXT
Note: See TracBrowser for help on using the browser.