Django

Code

Changeset 7666

Show
Ignore:
Timestamp:
06/16/08 11:58:12 (5 months ago)
Author:
jbronn
Message:

gis: Improvements to get_srid_info, including raising no exception when the srid == -1 and making the error checking and message more robust; tweaked testing tolerance in distapp for those running older versions of GEOS.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/models.py

    r7641 r7666  
    227227        during field initialization). 
    228228        """ 
     229        # SRID=-1 is a common convention for indicating the geometry has no 
     230        # spatial reference information associated with it.  Thus, we will 
     231        # return all None values without raising an exception. 
     232        if srid == -1: return None, None, None 
     233 
     234        # Getting the spatial reference WKT associated with the SRID from the 
     235        # `spatial_ref_sys` (or equivalent) spatial database table. This query 
     236        # cannot be executed using the ORM because this information is needed 
     237        # when the ORM cannot be used (e.g., during the initialization of  
     238        # `GeometryField`). 
    229239        from django.db import connection 
    230         # Getting the spatial reference WKT associated with the SRID from the 
    231         # `spatial_ref_sys` (or equivalent) spatial database table. 
    232         # 
    233         # The following doesn't work: SpatialRefSys.objects.get(srid=srid) 
    234         # Why?  `syncdb` fails to recognize installed geographic models when there's 
    235         # an ORM query instantiated within a model field. 
    236240        cur = connection.cursor() 
    237241        qn = connection.ops.quote_name 
     
    243247                       } 
    244248        cur.execute(stmt) 
    245         srs_wkt = cur.fetchone()[0] 
    246         if srs_wkt is None: 
    247             raise ValueError('Failed to find Spatial Reference System entry corresponding to SRID=%s' % srid) 
     249         
     250        # Fetching the WKT from the cursor; if the query failed raise an Exception. 
     251        fetched = cur.fetchone() 
     252        if not fetched: 
     253            raise ValueError('Failed to find spatial reference entry in "%s" corresponding to SRID=%s.' %  
     254                             (SpatialRefSys._meta.db_table, srid)) 
     255        srs_wkt = fetched[0] 
    248256 
    249257        # Getting metadata associated with the spatial reference system identifier. 
  • django/branches/gis/django/contrib/gis/tests/distapp/tests.py

    r7641 r7666  
    274274        qs = Interstate.objects.length() 
    275275        if oracle: tol = 2 
    276         else: tol = 7 
     276        else: tol = 5 
    277277        self.assertAlmostEqual(len_m, qs[0].length.m, tol) 
    278278