summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-04-07 22:20:58 +0000
committerJustin Bronn <jbronn@gmail.com>2008-04-07 22:20:58 +0000
commite1d84dd4fb3b53905e8bbc92a8233b9b65b7a0bd (patch)
treee9764660f5d01ea0f8d6b91923780a01d0d1992a
parent55ea575548ffc382fb4885da5a6a6fa331945259 (diff)
gis: Applied DRY to Oracle and MySQL geometry adaptors; the `PostGISAdaptor` now stores WKB in raw string form to support pickling; added an equivalence method to all adaptors.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7407 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/gis/db/backend/__init__.py6
-rw-r--r--django/contrib/gis/db/backend/adaptor.py13
-rw-r--r--django/contrib/gis/db/backend/mysql/adaptor.py10
-rw-r--r--django/contrib/gis/db/backend/oracle/adaptor.py11
-rw-r--r--django/contrib/gis/db/backend/postgis/adaptor.py10
-rw-r--r--django/contrib/gis/db/models/query.py2
6 files changed, 23 insertions, 29 deletions
diff --git a/django/contrib/gis/db/backend/__init__.py b/django/contrib/gis/db/backend/__init__.py
index e797942c0e..9b4bc20ae8 100644
--- a/django/contrib/gis/db/backend/__init__.py
+++ b/django/contrib/gis/db/backend/__init__.py
@@ -47,8 +47,7 @@ if settings.DATABASE_ENGINE == 'postgresql_psycopg2':
VERSION = (MAJOR_VERSION, MINOR_VERSION1, MINOR_VERSION2)
SPATIAL_BACKEND = 'postgis'
elif settings.DATABASE_ENGINE == 'oracle':
- from django.contrib.gis.db.backend.oracle.adaptor import \
- OracleSpatialAdaptor as GeoAdaptor
+ from django.contrib.gis.db.backend.adaptor import WKTAdaptor as GeoAdaptor
from django.contrib.gis.db.backend.oracle.field import \
OracleSpatialField as GeoBackendField
from django.contrib.gis.db.backend.oracle.creation import create_spatial_db
@@ -58,8 +57,7 @@ elif settings.DATABASE_ENGINE == 'oracle':
SPATIAL_BACKEND = 'oracle'
LIMITED_WHERE = ['relate']
elif settings.DATABASE_ENGINE == 'mysql':
- from django.contrib.gis.db.backend.mysql.adaptor import \
- MySQLAdaptor as GeoAdaptor
+ from django.contrib.gis.db.backend.adaptor import WKTAdaptor as GeoAdaptor
from django.contrib.gis.db.backend.mysql.field import \
MySQLGeoField as GeoBackendField
from django.contrib.gis.db.backend.mysql.creation import create_spatial_db
diff --git a/django/contrib/gis/db/backend/adaptor.py b/django/contrib/gis/db/backend/adaptor.py
new file mode 100644
index 0000000000..1f01cb01e2
--- /dev/null
+++ b/django/contrib/gis/db/backend/adaptor.py
@@ -0,0 +1,13 @@
+class WKTAdaptor(object):
+ """
+ This provides an adaptor for Geometries sent to the
+ MySQL and Oracle database backends.
+ """
+ def __init__(self, geom):
+ self.wkt = geom.wkt
+
+ def __eq__(self, other):
+ return self.wkt == other.wkt
+
+ def __str__(self):
+ return self.wkt
diff --git a/django/contrib/gis/db/backend/mysql/adaptor.py b/django/contrib/gis/db/backend/mysql/adaptor.py
deleted file mode 100644
index 9a702d3fdf..0000000000
--- a/django/contrib/gis/db/backend/mysql/adaptor.py
+++ /dev/null
@@ -1,10 +0,0 @@
-"""
- This object provides quoting for GEOS geometries into MySQL.
-"""
-class MySQLAdaptor(object):
- def __init__(self, geom):
- self.wkt = geom.wkt
-
- def __str__(self):
- "WKT is used as for the substitution value for the geometry."
- return self.wkt
diff --git a/django/contrib/gis/db/backend/oracle/adaptor.py b/django/contrib/gis/db/backend/oracle/adaptor.py
deleted file mode 100644
index 7b1caa2ad9..0000000000
--- a/django/contrib/gis/db/backend/oracle/adaptor.py
+++ /dev/null
@@ -1,11 +0,0 @@
-"""
- This object provides the database adaptor for Oracle geometries.
-"""
-class OracleSpatialAdaptor(object):
- def __init__(self, geom):
- "Initializes only on the geometry object."
- self.wkt = geom.wkt
-
- def __str__(self):
- "WKT is used for the substitution value of the geometry."
- return self.wkt
diff --git a/django/contrib/gis/db/backend/postgis/adaptor.py b/django/contrib/gis/db/backend/postgis/adaptor.py
index e91834722b..c094a9825a 100644
--- a/django/contrib/gis/db/backend/postgis/adaptor.py
+++ b/django/contrib/gis/db/backend/postgis/adaptor.py
@@ -8,9 +8,10 @@ from psycopg2.extensions import ISQLQuote
class PostGISAdaptor(object):
def __init__(self, geom):
- "Initializes on the geometry and the SRID."
- # Getting the WKB and the SRID
- self.wkb = geom.wkb
+ "Initializes on the geometry."
+ # Getting the WKB (in string form, to allow easy pickling of
+ # the adaptor) and the SRID from the geometry.
+ self.wkb = str(geom.wkb)
self.srid = geom.srid
def __conform__(self, proto):
@@ -20,6 +21,9 @@ class PostGISAdaptor(object):
else:
raise Exception('Error implementing psycopg2 protocol. Is psycopg2 installed?')
+ def __eq__(self, other):
+ return (self.wkb == other.wkb) and (self.srid == other.srid)
+
def __str__(self):
return self.getquoted()
diff --git a/django/contrib/gis/db/models/query.py b/django/contrib/gis/db/models/query.py
index f2cbcd15de..6550f0b6e4 100644
--- a/django/contrib/gis/db/models/query.py
+++ b/django/contrib/gis/db/models/query.py
@@ -291,7 +291,7 @@ class GeoQuerySet(QuerySet):
# some error checking is required.
if not isinstance(geo_field, PointField):
raise TypeError('Spherical distance calculation only supported on PointFields.')
- if not isinstance(GEOSGeometry(params[0].wkb), Point):
+ if not isinstance(GEOSGeometry(buffer(params[0].wkb)), Point):
raise TypeError('Spherical distance calculation only supported with Point Geometry parameters')
# Call to distance_spheroid() requires the spheroid as well.