1
0
mirror of https://github.com/django/django.git synced 2025-07-04 01:39:20 +00:00

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
This commit is contained in:
Justin Bronn 2008-04-07 22:20:58 +00:00
parent 55ea575548
commit e1d84dd4fb
6 changed files with 23 additions and 29 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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.