1 from django.db.models import Aggregate |
1 from django.db.models import Aggregate |
2 from django.contrib.gis.db.backend import SpatialBackend |
|
3 from django.contrib.gis.db.models.sql import GeomField |
2 from django.contrib.gis.db.models.sql import GeomField |
4 |
3 |
5 class GeoAggregate(Aggregate): |
4 class Collect(Aggregate): |
6 |
|
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) |
|
11 |
|
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 |
|
18 |
|
19 super(GeoAggregate, self).add_to_query(query, alias, col, source, is_summary) |
|
20 |
|
21 class Collect(GeoAggregate): |
|
22 name = 'Collect' |
5 name = 'Collect' |
23 |
6 |
24 class Extent(GeoAggregate): |
7 class Extent(Aggregate): |
25 name = 'Extent' |
8 name = 'Extent' |
26 |
9 |
27 class MakeLine(GeoAggregate): |
10 class Extent3D(Aggregate): |
|
11 name = 'Extent3D' |
|
12 |
|
13 class MakeLine(Aggregate): |
28 name = 'MakeLine' |
14 name = 'MakeLine' |
29 |
15 |
30 class Union(GeoAggregate): |
16 class Union(Aggregate): |
31 name = 'Union' |
17 name = 'Union' |