From 1ee9c5b4a965aaec7ab230295dcd4b99e330ab03 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sun, 10 Apr 2016 19:55:29 +0200 Subject: Refs #17635 -- Tested the Cast function in a geography to geometry context Thanks Tim Graham for the review. --- docs/ref/contrib/gis/model-api.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'docs') diff --git a/docs/ref/contrib/gis/model-api.txt b/docs/ref/contrib/gis/model-api.txt index d5e1d79afa..f795ea7c20 100644 --- a/docs/ref/contrib/gis/model-api.txt +++ b/docs/ref/contrib/gis/model-api.txt @@ -235,6 +235,18 @@ available for geography columns: * :lookup:`covers` * :lookup:`intersects` +If you need to use a spatial lookup or aggregate that doesn't support the +geography type as input, you can use the +:class:`~django.db.models.functions.Cast` database function to convert the +geography column to a geometry type in the query:: + + from django.contrib.gis.db.models import PointField + from django.db.models.functions import Cast + + Zipcode.objects.annotate( + geom=Cast('geography_field', PointField()) + ).filter(geom__within=poly) + For more information, the PostGIS documentation contains a helpful section on determining `when to use geography data type over geometry data type `_. -- cgit v1.3