﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17635	Missing ability to cast georaphy to geometry when using GeoDjango and PostgresSQL	corentin.chary@…	nobody	"Looking at http://postgis.refractions.net/docs/ch08.html#PostGIS_TypeFunctionMatrix you will see that a lot of functions only work on geometric fields (ie: geography=False).

That means something like Markers.objects.extent() won't work if the coordinate field of Marker have geography set to True because the underlying function (ST_Extent()) only work with geometric fields.

A workaround (if you don't really care about precision) is to cast geography to geometry:

   SELECT ST_Extent(coordinates::geometry) FROM markers;

That will perfectly work. However, you can't really do that with django. The best you can do seems to be:

   qs.extra(select={'extent': 'ST_Extent(""coordinates""::geometry)'}).values('extent')

But that's really far from perfect.

Here are some propositions:
- add a way to cast to geometry, that would allow to do: `qs.extent(field_name=coordinates__geometry)` (the trailing `__geometry` cast a GeometryField from geography to geometry)
- another way to cast to geometry would be: `qs.geometry('coordinates').extent()`
- automatically cast geography to geometry if a function only support geometry (hum...)
"	New feature	new	GIS	dev	Normal				Design decision needed	0	0	0	0	0	0
