1
1
from django.db.models import Aggregate
2
from django.contrib.gis.db.backend import SpatialBackend
3
2
from django.contrib.gis.db.models.sql import GeomField
5
class GeoAggregate(Aggregate):
7
def add_to_query(self, query, alias, col, source, is_summary):
8
if hasattr(source, 'geom_type'):
9
# Doing additional setup on the Query object for spatial aggregates.
10
aggregate = getattr(query.aggregates_module, self.name)
12
# Adding a conversion class instance and any selection wrapping
13
# SQL (e.g., needed by Oracle).
14
if aggregate.conversion_class is GeomField:
15
query.extra_select_fields[alias] = GeomField()
16
if SpatialBackend.select:
17
query.custom_select[alias] = SpatialBackend.select
19
super(GeoAggregate, self).add_to_query(query, alias, col, source, is_summary)
21
class Collect(GeoAggregate):
4
class Collect(Aggregate):
24
class Extent(GeoAggregate):
7
class Extent(Aggregate):
27
class MakeLine(GeoAggregate):
10
class Extent3D(Aggregate):
13
class MakeLine(Aggregate):
30
class Union(GeoAggregate):
16
class Union(Aggregate):