Ticket #12733: extent-patch.diff
File extent-patch.diff, 2.7 KB (added by , 15 years ago) |
---|
-
django/contrib/gis/db/backends/mysql/operations.py
11 11 select = 'AsText(%s)' 12 12 from_wkb = 'GeomFromWKB' 13 13 from_text = 'GeomFromText' 14 valid_aggregates = dict([(k, None) for k in ('Extent',)]) 14 15 16 extent_sql = '''CONCAT_WS(',', MAX(X(%(field)s)), MAX(Y(%(field)s)), MIN(X(%(field)s)), MIN(Y(%(field)s)))''' 17 extent = 'Extent' 18 15 19 Adapter = WKTAdapter 16 20 17 21 geometry_functions = { … … 31 35 32 36 gis_terms = dict([(term, None) for term in geometry_functions.keys() + ['isnull']]) 33 37 38 def convert_extent (self,box): 39 """ 40 Returns a 4-tuple extent for the `Extent` aggregate, created by MIN/MAX 41 queries on the dataset 42 """ 43 xmax, ymax, xmin, ymin = map(float, box.split(',')) 44 return (xmin, ymin, xmax, ymax) 45 46 def check_aggregate_support(self, aggregate): 47 """ 48 Checks if the given aggregate name is supported (that is, if it's 49 in `self.valid_aggregates`). 50 """ 51 agg_name = aggregate.__class__.__name__ 52 return agg_name in self.valid_aggregates 53 34 54 def geo_db_type(self, f): 35 55 return f.geom_type 36 56 … … 46 66 placeholder = '%s(%%s)' % self.from_text 47 67 return placeholder 48 68 69 70 def spatial_aggregate_sql(self, agg): 71 """ 72 Returns the spatial aggregate SQL template and function for the 73 given Aggregate instance. 74 """ 75 agg_name = agg.__class__.__name__ 76 if not self.check_aggregate_support(agg): 77 raise NotImplementedError('%s spatial aggregate is not implmented for this backend.' % agg_name) 78 agg_name = agg_name.lower() 79 sql_template = getattr(self, agg_name + '_sql') 80 sql_function = getattr(self, agg_name) 81 return sql_template, sql_function 82 49 83 def spatial_lookup_sql(self, lvalue, lookup_type, value, field, qn): 50 84 alias, col, db_type = lvalue 51 85 -
django/contrib/gis/tests/relatedapp/tests.py
56 56 qs = list(City.objects.filter(name=name).transform(srid, field_name='location__point')) 57 57 check_pnt(GEOSGeometry(wkt, srid), qs[0].location.point) 58 58 59 @no_mysql60 59 @no_spatialite 61 60 def test04a_related_extent_aggregate(self): 62 61 "Testing the `extent` GeoQuerySet aggregates on related geographic models."