Changeset 7666 for django/branches/gis/django/contrib/gis/models.py
- Timestamp:
- 06/16/08 11:58:12 (7 months ago)
- Files:
-
- django/branches/gis/django/contrib/gis/models.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/models.py
r7641 r7666 227 227 during field initialization). 228 228 """ 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`). 229 239 from django.db import connection 230 # Getting the spatial reference WKT associated with the SRID from the231 # `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's235 # an ORM query instantiated within a model field.236 240 cur = connection.cursor() 237 241 qn = connection.ops.quote_name … … 243 247 } 244 248 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] 248 256 249 257 # Getting metadata associated with the spatial reference system identifier.
