1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

gis: The WKTAdaptor needs the SRID for Oracle; now test geodetic dwithin lookups on Oracle.

git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7464 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2008-04-26 00:36:15 +00:00
parent c03a030fd3
commit 5456919782
2 changed files with 29 additions and 13 deletions

View File

@ -5,9 +5,10 @@ class WKTAdaptor(object):
""" """
def __init__(self, geom): def __init__(self, geom):
self.wkt = geom.wkt self.wkt = geom.wkt
self.srid = geom.srid
def __eq__(self, other): def __eq__(self, other):
return self.wkt == other.wkt return self.wkt == other.wkt and self.srid == other.srid
def __str__(self): def __str__(self):
return self.wkt return self.wkt

View File

@ -41,21 +41,36 @@ class DistanceTest(unittest.TestCase):
def test02_dwithin(self): def test02_dwithin(self):
"Testing the `dwithin` lookup type." "Testing the `dwithin` lookup type."
pnt = self.stx_pnt # Distances -- all should be equal (except for the
dists = [7000, D(km=7), D(mi=4.349)] # degree/meter pair in au_cities, that's somewhat
for dist in dists: # approximate).
qs = SouthTexasCity.objects.filter(point__dwithin=(self.stx_pnt, dist)) tx_dists = [7000, D(km=7), D(mi=4.349)]
self.assertEqual(['Downtown Houston', 'Southside Place'], self.get_cities(qs)) au_dists = [(0.5, 32000), D(km=32), D(mi=19.884)]
if isinstance(dist, D): # Expected cities for Australia and Texas.
# A TypeError should be raised when trying to pass Distance objects tx_cities = ['Downtown Houston', 'Southside Place']
# into a DWithin query using a geodetic field. au_cities = ['Mittagong', 'Shellharbour', 'Thirroul', 'Wollongong']
qs = AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, dist))
for dist in tx_dists:
qs = SouthTexasCity.objects.filter(point__dwithin=(self.stx_pnt, dist))
self.assertEqual(tx_cities, self.get_cities(qs))
for dist in au_dists:
if isinstance(dist, D) and not oracle: type_error = True
else: type_error = False
if isinstance(dist, tuple):
if oracle: dist = dist[1]
else: dist = dist[0]
# Creating the query set.
qs = AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, dist)).order_by('name')
if type_error:
# A TypeError should be raised on PostGIS when trying to pass
# Distance objects into a DWithin query using a geodetic field.
self.assertRaises(TypeError, qs.count) self.assertRaises(TypeError, qs.count)
else: else:
# Actually using a distance value of 0.5 degrees. self.assertEqual(au_cities, self.get_cities(qs))
qs = AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, 0.5)).order_by('name')
self.assertEqual(['Mittagong', 'Shellharbour', 'Thirroul', 'Wollongong'], self.get_cities(qs))
def test03_distance_aggregate(self): def test03_distance_aggregate(self):
"Testing the `distance` GeoQuerySet method." "Testing the `distance` GeoQuerySet method."