summaryrefslogtreecommitdiff
path: root/django/contrib/gis/db/models/sql/query.py
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2009-03-30 17:15:49 +0000
committerJustin Bronn <jbronn@gmail.com>2009-03-30 17:15:49 +0000
commit867e71501c3273ba4a0b3ac13847cd895f0da663 (patch)
tree3046e8cfa9fc04257d4f147aae533dcc2fd7e88a /django/contrib/gis/db/models/sql/query.py
parenta61c0b7949f90fa43cac9ee5b35a8dc825dd49ea (diff)
Refactored and cleaned up parts of the spatial database backend. Changes include:
* Laid foundations for SpatiaLite support in `GeoQuerySet`, `GeoWhereNode` and the tests. * Added the `Collect` aggregate for PostGIS (still needs tests). * Oracle now goes to 11. * The backend-specific `SpatialRefSys` and `GeometryColumns` models are now attributes of `SpatialBackend`. * Renamed `GeometryField` attributes to be public that were private (e.g., `_srid` -> `srid` and `_geom` -> `geom_type`). * Renamed `create_test_db` to `create_test_spatial_db`. * Removed the legacy classes `GeoMixin` and `GeoQ`. * Removed evil `\` from spatial backend fields. * Moved shapefile data from `tests/layermap` to `tests/data`. Fixed #9794. Refs #9686. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10197 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/gis/db/models/sql/query.py')
-rw-r--r--django/contrib/gis/db/models/sql/query.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/django/contrib/gis/db/models/sql/query.py b/django/contrib/gis/db/models/sql/query.py
index 712316e434..e09cb7ce3c 100644
--- a/django/contrib/gis/db/models/sql/query.py
+++ b/django/contrib/gis/db/models/sql/query.py
@@ -208,13 +208,14 @@ class GeoQuery(sql.Query):
if SpatialBackend.oracle:
# Running through Oracle's first.
value = super(GeoQuery, self).convert_values(value, field or GeomField())
+
if isinstance(field, DistanceField):
# Using the field's distance attribute, can instantiate
# `Distance` with the right context.
value = Distance(**{field.distance_att : value})
elif isinstance(field, AreaField):
value = Area(**{field.area_att : value})
- elif isinstance(field, GeomField):
+ elif isinstance(field, GeomField) and value:
value = SpatialBackend.Geometry(value)
return value
@@ -260,7 +261,7 @@ class GeoQuery(sql.Query):
selection formats in order to retrieve geometries in OGC WKT. For all
other fields a simple '%s' format string is returned.
"""
- if SpatialBackend.select and hasattr(fld, '_geom'):
+ if SpatialBackend.select and hasattr(fld, 'geom_type'):
# This allows operations to be done on fields in the SELECT,
# overriding their values -- used by the Oracle and MySQL
# spatial backends to get database values as WKT, and by the
@@ -270,8 +271,10 @@ class GeoQuery(sql.Query):
# Because WKT doesn't contain spatial reference information,
# the SRID is prefixed to the returned WKT to ensure that the
# transformed geometries have an SRID different than that of the
- # field -- this is only used by `transform` for Oracle backends.
- if self.transformed_srid and SpatialBackend.oracle:
+ # field -- this is only used by `transform` for Oracle and
+ # SpatiaLite backends.
+ if self.transformed_srid and ( SpatialBackend.oracle or
+ SpatialBackend.spatialite ):
sel_fmt = "'SRID=%d;'||%s" % (self.transformed_srid, sel_fmt)
else:
sel_fmt = '%s'