Commit 867e7150 authored by Justin Bronn's avatar Justin Bronn
Browse files

Refactored and cleaned up parts of the spatial database backend. Changes include:

* Laid foundations for SpatiaLite support in `GeoQuerySet`, `GeoWhereNode` and the tests.
* Added the `Collect` aggregate for PostGIS (still needs tests).
* Oracle now goes to 11.
* The backend-specific `SpatialRefSys` and `GeometryColumns` models are now attributes of `SpatialBackend`.
* Renamed `GeometryField` attributes to be public that were private (e.g., `_srid` -> `srid` and `_geom` -> `geom_type`).
* Renamed `create_test_db` to `create_test_spatial_db`.
* Removed the legacy classes `GeoMixin` and `GeoQ`.
* Removed evil `\` from spatial backend fields.
* Moved shapefile data from `tests/layermap` to `tests/data`.

Fixed #9794.  Refs #9686.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@10197 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent a61c0b79
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -9,10 +9,12 @@ from django.contrib.gis.db.backend.util import gqn

# Retrieving the necessary settings from the backend.
if settings.DATABASE_ENGINE == 'postgresql_psycopg2':
    from django.contrib.gis.db.backend.postgis import create_spatial_db, get_geo_where_clause, SpatialBackend
    from django.contrib.gis.db.backend.postgis import create_test_spatial_db, get_geo_where_clause, SpatialBackend
elif settings.DATABASE_ENGINE == 'oracle':
    from django.contrib.gis.db.backend.oracle import create_spatial_db, get_geo_where_clause, SpatialBackend
    from django.contrib.gis.db.backend.oracle import create_test_spatial_db, get_geo_where_clause, SpatialBackend
elif settings.DATABASE_ENGINE == 'mysql':
    from django.contrib.gis.db.backend.mysql import create_spatial_db, get_geo_where_clause, SpatialBackend
    from django.contrib.gis.db.backend.mysql import create_test_spatial_db, get_geo_where_clause, SpatialBackend
elif settings.DATABASE_ENGINE == 'sqlite3':
    from django.contrib.gis.db.backend.spatialite import create_test_spatial_db, get_geo_where_clause, SpatialBackend
else:
    raise NotImplementedError('No Geographic Backend exists for %s' % settings.DATABASE_ENGINE)
+1 −4
Original line number Diff line number Diff line
@@ -24,6 +24,3 @@ class BaseSpatialBackend(object):
        except KeyError:
            return False
        
        
    
+2 −2
Original line number Diff line number Diff line
__all__ = ['create_spatial_db', 'get_geo_where_clause', 'SpatialBackend']
__all__ = ['create_test_spatial_db', 'get_geo_where_clause', 'SpatialBackend']

from django.contrib.gis.db.backend.base import BaseSpatialBackend
from django.contrib.gis.db.backend.adaptor import WKTAdaptor
from django.contrib.gis.db.backend.mysql.creation import create_spatial_db
from django.contrib.gis.db.backend.mysql.creation import create_test_spatial_db
from django.contrib.gis.db.backend.mysql.field import MySQLGeoField
from django.contrib.gis.db.backend.mysql.query import *

+2 −2
Original line number Diff line number Diff line

def create_spatial_db(test=True, verbosity=1, autoclobber=False):
    if not test: raise NotImplementedError('This uses `create_test_db` from test/utils.py')
def create_test_spatial_db(verbosity=1, autoclobber=False):
    "A wrapper over the MySQL `create_test_db` method."
    from django.db import connection
    connection.creation.create_test_db(verbosity, autoclobber)
+12 −12
Original line number Diff line number Diff line
@@ -22,11 +22,11 @@ class MySQLGeoField(Field):
        # Getting the index name.
        idx_name = '%s_%s_id' % (db_table, self.column)

        sql = style.SQL_KEYWORD('CREATE SPATIAL INDEX ') + \
              style.SQL_TABLE(qn(idx_name)) + \
              style.SQL_KEYWORD(' ON ') + \
              style.SQL_TABLE(qn(db_table)) + '(' + \
              style.SQL_FIELD(qn(self.column)) + ');'
        sql = (style.SQL_KEYWORD('CREATE SPATIAL INDEX ') +
               style.SQL_TABLE(qn(idx_name)) +
               style.SQL_KEYWORD(' ON ') +
               style.SQL_TABLE(qn(db_table)) + '(' +
               style.SQL_FIELD(qn(self.column)) + ');')
        return sql

    def post_create_sql(self, style, db_table):
@@ -35,14 +35,14 @@ class MySQLGeoField(Field):
        created.
        """
        # Getting the geometric index for this Geometry column.
        if self._index:
        if self.spatial_index:
            return (self._geom_index(style, db_table),)
        else:
            return ()

    def db_type(self):
        "The OpenGIS name is returned for the MySQL database column type."
        return self._geom
        return self.geom_type

    def get_placeholder(self, value):
        """
Loading