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:
parent
55ea575548
commit
e1d84dd4fb
@ -47,8 +47,7 @@ if settings.DATABASE_ENGINE == 'postgresql_psycopg2':
|
|||||||
VERSION = (MAJOR_VERSION, MINOR_VERSION1, MINOR_VERSION2)
|
VERSION = (MAJOR_VERSION, MINOR_VERSION1, MINOR_VERSION2)
|
||||||
SPATIAL_BACKEND = 'postgis'
|
SPATIAL_BACKEND = 'postgis'
|
||||||
elif settings.DATABASE_ENGINE == 'oracle':
|
elif settings.DATABASE_ENGINE == 'oracle':
|
||||||
from django.contrib.gis.db.backend.oracle.adaptor import \
|
from django.contrib.gis.db.backend.adaptor import WKTAdaptor as GeoAdaptor
|
||||||
OracleSpatialAdaptor as GeoAdaptor
|
|
||||||
from django.contrib.gis.db.backend.oracle.field import \
|
from django.contrib.gis.db.backend.oracle.field import \
|
||||||
OracleSpatialField as GeoBackendField
|
OracleSpatialField as GeoBackendField
|
||||||
from django.contrib.gis.db.backend.oracle.creation import create_spatial_db
|
from django.contrib.gis.db.backend.oracle.creation import create_spatial_db
|
||||||
@ -58,8 +57,7 @@ elif settings.DATABASE_ENGINE == 'oracle':
|
|||||||
SPATIAL_BACKEND = 'oracle'
|
SPATIAL_BACKEND = 'oracle'
|
||||||
LIMITED_WHERE = ['relate']
|
LIMITED_WHERE = ['relate']
|
||||||
elif settings.DATABASE_ENGINE == 'mysql':
|
elif settings.DATABASE_ENGINE == 'mysql':
|
||||||
from django.contrib.gis.db.backend.mysql.adaptor import \
|
from django.contrib.gis.db.backend.adaptor import WKTAdaptor as GeoAdaptor
|
||||||
MySQLAdaptor as GeoAdaptor
|
|
||||||
from django.contrib.gis.db.backend.mysql.field import \
|
from django.contrib.gis.db.backend.mysql.field import \
|
||||||
MySQLGeoField as GeoBackendField
|
MySQLGeoField as GeoBackendField
|
||||||
from django.contrib.gis.db.backend.mysql.creation import create_spatial_db
|
from django.contrib.gis.db.backend.mysql.creation import create_spatial_db
|
||||||
|
13
django/contrib/gis/db/backend/adaptor.py
Normal file
13
django/contrib/gis/db/backend/adaptor.py
Normal 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
|
@ -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
|
|
@ -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
|
|
@ -8,9 +8,10 @@ from psycopg2.extensions import ISQLQuote
|
|||||||
|
|
||||||
class PostGISAdaptor(object):
|
class PostGISAdaptor(object):
|
||||||
def __init__(self, geom):
|
def __init__(self, geom):
|
||||||
"Initializes on the geometry and the SRID."
|
"Initializes on the geometry."
|
||||||
# Getting the WKB and the SRID
|
# Getting the WKB (in string form, to allow easy pickling of
|
||||||
self.wkb = geom.wkb
|
# the adaptor) and the SRID from the geometry.
|
||||||
|
self.wkb = str(geom.wkb)
|
||||||
self.srid = geom.srid
|
self.srid = geom.srid
|
||||||
|
|
||||||
def __conform__(self, proto):
|
def __conform__(self, proto):
|
||||||
@ -20,6 +21,9 @@ class PostGISAdaptor(object):
|
|||||||
else:
|
else:
|
||||||
raise Exception('Error implementing psycopg2 protocol. Is psycopg2 installed?')
|
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):
|
def __str__(self):
|
||||||
return self.getquoted()
|
return self.getquoted()
|
||||||
|
|
||||||
|
@ -291,7 +291,7 @@ class GeoQuerySet(QuerySet):
|
|||||||
# some error checking is required.
|
# some error checking is required.
|
||||||
if not isinstance(geo_field, PointField):
|
if not isinstance(geo_field, PointField):
|
||||||
raise TypeError('Spherical distance calculation only supported on PointFields.')
|
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')
|
raise TypeError('Spherical distance calculation only supported with Point Geometry parameters')
|
||||||
|
|
||||||
# Call to distance_spheroid() requires the spheroid as well.
|
# Call to distance_spheroid() requires the spheroid as well.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user