mirror of
https://github.com/django/django.git
synced 2025-01-11 19:06:26 +00:00
Fixed #17448 -- Improved test and documented raw-sql gis query
This commit is contained in:
parent
e6e01f619d
commit
62e1c5a441
@ -189,7 +189,9 @@ class GeoModelTest(TestCase):
|
|||||||
def test_raw_sql_query(self):
|
def test_raw_sql_query(self):
|
||||||
"Testing raw SQL query."
|
"Testing raw SQL query."
|
||||||
cities1 = City.objects.all()
|
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.assertEqual(len(cities1), len(list(cities2)))
|
||||||
self.assertTrue(isinstance(cities2[0].point, Point))
|
self.assertTrue(isinstance(cities2[0].point, Point))
|
||||||
|
|
||||||
|
@ -671,6 +671,17 @@ of abstraction::
|
|||||||
|
|
||||||
__ http://spatialreference.org/ref/epsg/32140/
|
__ http://spatialreference.org/ref/epsg/32140/
|
||||||
|
|
||||||
|
.. admonition:: Raw queries
|
||||||
|
|
||||||
|
When using :doc:`raw queries </topics/db/sql>`, 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
|
Lazy Geometries
|
||||||
---------------
|
---------------
|
||||||
Geometries come to GeoDjango in a standardized textual representation. Upon
|
Geometries come to GeoDjango in a standardized textual representation. Upon
|
||||||
|
Loading…
Reference in New Issue
Block a user