From 62e1c5a441d957e44d7527a6d901587b40203a51 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 25 Aug 2012 14:37:00 +0200 Subject: [PATCH] Fixed #17448 -- Improved test and documented raw-sql gis query --- django/contrib/gis/tests/geoapp/tests.py | 4 +++- docs/ref/contrib/gis/tutorial.txt | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/django/contrib/gis/tests/geoapp/tests.py b/django/contrib/gis/tests/geoapp/tests.py index d989b50ada..fbe30e8841 100644 --- a/django/contrib/gis/tests/geoapp/tests.py +++ b/django/contrib/gis/tests/geoapp/tests.py @@ -189,7 +189,9 @@ class GeoModelTest(TestCase): def test_raw_sql_query(self): "Testing raw SQL query." cities1 = City.objects.all() - cities2 = City.objects.raw('select * from geoapp_city') + # Only PostGIS would support a 'select *' query because of its recognized + # HEXEWKB format for geometry fields + cities2 = City.objects.raw('select id, name, asText(point) from geoapp_city') self.assertEqual(len(cities1), len(list(cities2))) self.assertTrue(isinstance(cities2[0].point, Point)) diff --git a/docs/ref/contrib/gis/tutorial.txt b/docs/ref/contrib/gis/tutorial.txt index 3a63493137..15863aee7b 100644 --- a/docs/ref/contrib/gis/tutorial.txt +++ b/docs/ref/contrib/gis/tutorial.txt @@ -671,6 +671,17 @@ of abstraction:: __ http://spatialreference.org/ref/epsg/32140/ +.. admonition:: Raw queries + + When using :doc:`raw queries `, you should generally wrap + your geometry fields with the ``asText()`` SQL function so as the field + value will be recognized by GEOS:: + + City.objects.raw('SELECT id, name, asText(point) from myapp_city') + + This is not absolutely required by PostGIS, but generally you should only + use raw queries when you know exactly what you are doing. + Lazy Geometries --------------- Geometries come to GeoDjango in a standardized textual representation. Upon