Django

Code

Changeset 7464

Show
Ignore:
Timestamp:
04/25/08 19:36:15 (4 months ago)
Author:
jbronn
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/db/backend/adaptor.py

    r7407 r7464  
    66    def __init__(self, geom): 
    77        self.wkt = geom.wkt 
     8        self.srid = geom.srid 
    89 
    910    def __eq__(self, other): 
    10         return self.wkt == other.wkt 
     11        return self.wkt == other.wkt and self.srid == other.srid  
    1112 
    1213    def __str__(self): 
  • django/branches/gis/django/contrib/gis/tests/distapp/tests.py

    r7456 r7464  
    4242    def test02_dwithin(self): 
    4343        "Testing the `dwithin` lookup type." 
    44         pnt = self.stx_pnt 
    45         dists = [7000, D(km=7), D(mi=4.349)] 
    46         for dist in dists: 
     44        # Distances -- all should be equal (except for the 
     45        # degree/meter pair in au_cities, that's somewhat 
     46        # approximate). 
     47        tx_dists = [7000, D(km=7), D(mi=4.349)] 
     48        au_dists = [(0.5, 32000), D(km=32), D(mi=19.884)] 
     49         
     50        # Expected cities for Australia and Texas. 
     51        tx_cities = ['Downtown Houston', 'Southside Place'] 
     52        au_cities = ['Mittagong', 'Shellharbour', 'Thirroul', 'Wollongong'] 
     53 
     54        for dist in tx_dists: 
    4755            qs = SouthTexasCity.objects.filter(point__dwithin=(self.stx_pnt, dist)) 
    48             self.assertEqual(['Downtown Houston', 'Southside Place'], self.get_cities(qs)) 
     56            self.assertEqual(tx_cities, self.get_cities(qs)) 
    4957 
    50             if isinstance(dist, D): 
    51                 # A TypeError should be raised when trying to pass Distance objects 
    52                 # into a DWithin query using a geodetic field. 
    53                 qs = AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, dist)) 
     58        for dist in au_dists: 
     59            if isinstance(dist, D) and not oracle: type_error = True 
     60            else: type_error = False 
     61 
     62            if isinstance(dist, tuple): 
     63                if oracle: dist = dist[1] 
     64                else: dist = dist[0] 
     65                 
     66            # Creating the query set. 
     67            qs = AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, dist)).order_by('name') 
     68            if type_error: 
     69                # A TypeError should be raised on PostGIS when trying to pass 
     70                # Distance objects into a DWithin query using a geodetic field.   
    5471                self.assertRaises(TypeError, qs.count) 
    5572            else: 
    56                 # Actually using a distance value of 0.5 degrees. 
    57                 qs = AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, 0.5)).order_by('name') 
    58                 self.assertEqual(['Mittagong', 'Shellharbour', 'Thirroul', 'Wollongong'], self.get_cities(qs)) 
     73                self.assertEqual(au_cities, self.get_cities(qs)) 
    5974 
    6075    def test03_distance_aggregate(self):