Loading django/contrib/gis/db/models/query.py +1 −97 Original line number Diff line number Diff line import warnings from django.contrib.gis.db.models import aggregates from django.contrib.gis.db.models.fields import ( GeometryField, LineStringField, PointField, get_srid_info, ) Loading @@ -15,9 +14,7 @@ from django.db.models.expressions import RawSQL from django.db.models.fields import Field from django.db.models.query import QuerySet from django.utils import six from django.utils.deprecation import ( RemovedInDjango20Warning, RemovedInDjango110Warning, ) from django.utils.deprecation import RemovedInDjango20Warning class GeoQuerySet(QuerySet): Loading Loading @@ -62,19 +59,6 @@ class GeoQuerySet(QuerySet): """ return self._geom_attribute('centroid', **kwargs) def collect(self, **kwargs): """ Performs an aggregate collect operation on the given geometry field. This is analogous to a union operation, but much faster because boundaries are not dissolved. """ warnings.warn( "The collect GeoQuerySet method is deprecated. Use the Collect() " "aggregate in an aggregate() or annotate() method.", RemovedInDjango110Warning, stacklevel=2 ) return self._spatial_aggregate(aggregates.Collect, **kwargs) def difference(self, geom, **kwargs): """ Returns the spatial difference of the geographic field in a `difference` Loading Loading @@ -108,31 +92,6 @@ class GeoQuerySet(QuerySet): """ return self._geom_attribute('envelope', **kwargs) def extent(self, **kwargs): """ Returns the extent (aggregate) of the features in the GeoQuerySet. The extent will be returned as a 4-tuple, consisting of (xmin, ymin, xmax, ymax). """ warnings.warn( "The extent GeoQuerySet method is deprecated. Use the Extent() " "aggregate in an aggregate() or annotate() method.", RemovedInDjango110Warning, stacklevel=2 ) return self._spatial_aggregate(aggregates.Extent, **kwargs) def extent3d(self, **kwargs): """ Returns the aggregate extent, in 3D, of the features in the GeoQuerySet. It is returned as a 6-tuple, comprising: (xmin, ymin, zmin, xmax, ymax, zmax). """ warnings.warn( "The extent3d GeoQuerySet method is deprecated. Use the Extent3D() " "aggregate in an aggregate() or annotate() method.", RemovedInDjango110Warning, stacklevel=2 ) return self._spatial_aggregate(aggregates.Extent3D, **kwargs) def force_rhr(self, **kwargs): """ Returns a modified version of the Polygon/MultiPolygon in which Loading Loading @@ -227,19 +186,6 @@ class GeoQuerySet(QuerySet): """ return self._distance_attribute('length', None, **kwargs) def make_line(self, **kwargs): """ Creates a linestring from all of the PointField geometries in the this GeoQuerySet and returns it. This is a spatial aggregate method, and thus returns a geometry rather than a GeoQuerySet. """ warnings.warn( "The make_line GeoQuerySet method is deprecated. Use the MakeLine() " "aggregate in an aggregate() or annotate() method.", RemovedInDjango110Warning, stacklevel=2 ) return self._spatial_aggregate(aggregates.MakeLine, geo_field_type=PointField, **kwargs) def mem_size(self, **kwargs): """ Returns the memory size (number of bytes) that the geometry field takes Loading Loading @@ -415,19 +361,6 @@ class GeoQuerySet(QuerySet): """ return self._geomset_attribute('union', geom, **kwargs) def unionagg(self, **kwargs): """ Performs an aggregate union on the given geometry field. Returns None if the GeoQuerySet is empty. The `tolerance` keyword is for Oracle backends only. """ warnings.warn( "The unionagg GeoQuerySet method is deprecated. Use the Union() " "aggregate in an aggregate() or annotate() method.", RemovedInDjango110Warning, stacklevel=2 ) return self._spatial_aggregate(aggregates.Union, **kwargs) # ### Private API -- Abstracted DRY routines. ### def _spatial_setup(self, att, desc=None, field_name=None, geo_field_type=None): """ Loading Loading @@ -462,35 +395,6 @@ class GeoQuerySet(QuerySet): return procedure_args, geo_field def _spatial_aggregate(self, aggregate, field_name=None, geo_field_type=None, tolerance=0.05): """ DRY routine for calling aggregate spatial stored procedures and returning their result to the caller of the function. """ # Getting the field the geographic aggregate will be called on. geo_field = self._geo_field(field_name) if not geo_field: raise TypeError('%s aggregate only available on GeometryFields.' % aggregate.name) # Checking if there are any geo field type limitations on this # aggregate (e.g. ST_Makeline only operates on PointFields). if geo_field_type is not None and not isinstance(geo_field, geo_field_type): raise TypeError('%s aggregate may only be called on %ss.' % (aggregate.name, geo_field_type.__name__)) # Getting the string expression of the field name, as this is the # argument taken by `Aggregate` objects. agg_col = field_name or geo_field.name # Adding any keyword parameters for the Aggregate object. Oracle backends # in particular need an additional `tolerance` parameter. agg_kwargs = {} if connections[self.db].ops.oracle: agg_kwargs['tolerance'] = tolerance # Calling the QuerySet.aggregate, and returning only the value of the aggregate. return self.aggregate(geoagg=aggregate(agg_col, **agg_kwargs))['geoagg'] def _spatial_attribute(self, att, settings, field_name=None, model_att=None): """ DRY routine for calling a spatial stored procedure on a geometry column Loading docs/ref/contrib/gis/geoquerysets.txt +0 −66 Original line number Diff line number Diff line Loading @@ -1216,72 +1216,6 @@ Returns the number of points in the first linestring in the geometry field in a ``num_points`` attribute on each element of the ``GeoQuerySet``; otherwise sets with ``None``. Spatial Aggregates ================== Aggregate Methods ----------------- .. deprecated:: 1.8 Aggregate methods are now deprecated. Prefer using their function-based equivalents. ``collect`` ~~~~~~~~~~~ .. method:: GeoQuerySet.collect(**kwargs) .. deprecated:: 1.8 Use the :class:`Collect` aggregate instead. Shortcut for ``aggregate(Collect(<field>))``. ``extent`` ~~~~~~~~~~ .. method:: GeoQuerySet.extent(**kwargs) .. deprecated:: 1.8 Use the :class:`Extent` aggregate instead. Shortcut for ``aggregate(Extent(<field>))``. ``extent3d`` ~~~~~~~~~~~~ .. method:: GeoQuerySet.extent3d(**kwargs) .. deprecated:: 1.8 Use the :class:`Extent` aggregate instead. Shortcut for ``aggregate(Extent3D(<field>))``. ``make_line`` ~~~~~~~~~~~~~ .. method:: GeoQuerySet.make_line(**kwargs) .. deprecated:: 1.8 Use the :class:`MakeLine` aggregate instead. Shortcut for ``aggregate(MakeLine(<field>))``. ``unionagg`` ~~~~~~~~~~~~ .. method:: GeoQuerySet.unionagg(**kwargs) .. deprecated:: 1.8 Use the :class:`Union` aggregate instead. Shortcut for ``aggregate(Union(<field>))``. Aggregate Functions ------------------- Loading docs/releases/1.2.txt +1 −2 Original line number Diff line number Diff line Loading @@ -358,8 +358,7 @@ Support for 3D geometry fields was added, and may be enabled by setting the :attr:`~django.contrib.gis.db.models.GeometryField.dim` keyword to 3 in your :class:`~django.contrib.gis.db.models.GeometryField`. The :class:`~django.contrib.gis.db.models.Extent3D` aggregate and :meth:`~django.contrib.gis.db.models.GeoQuerySet.extent3d` ``GeoQuerySet`` method were added as a part of this feature. and ``extent3d()`` ``GeoQuerySet`` method were added as a part of this feature. The following :class:`~django.contrib.gis.db.models.GeoQuerySet` methods are new in 1.2: Loading tests/gis_tests/geo3d/tests.py +3 −9 Original line number Diff line number Diff line Loading @@ -12,9 +12,7 @@ from django.contrib.gis.gdal import HAS_GDAL from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon from django.test import TestCase, ignore_warnings, skipUnlessDBFeature from django.utils._os import upath from django.utils.deprecation import ( RemovedInDjango20Warning, RemovedInDjango110Warning, ) from django.utils.deprecation import RemovedInDjango20Warning from .models import ( City3D, Interstate2D, Interstate3D, InterstateProj2D, InterstateProj3D, Loading Loading @@ -217,7 +215,6 @@ class Geo3DTest(Geo3DLoadingHelper, TestCase): self.assertSetEqual({p.ewkt for p in ref_union}, {p.ewkt for p in union}) @skipUnlessDBFeature("supports_3d_functions") @ignore_warnings(category=RemovedInDjango110Warning) def test_extent(self): """ Testing the Extent3D aggregate for 3D models. Loading @@ -225,16 +222,13 @@ class Geo3DTest(Geo3DLoadingHelper, TestCase): self._load_city_data() # `SELECT ST_Extent3D(point) FROM geo3d_city3d;` ref_extent3d = (-123.305196, -41.315268, 14, 174.783117, 48.462611, 1433) extent1 = City3D.objects.aggregate(Extent3D('point'))['point__extent3d'] extent2 = City3D.objects.extent3d() extent = City3D.objects.aggregate(Extent3D('point'))['point__extent3d'] def check_extent3d(extent3d, tol=6): for ref_val, ext_val in zip(ref_extent3d, extent3d): self.assertAlmostEqual(ref_val, ext_val, tol) for e3d in [extent1, extent2]: check_extent3d(e3d) self.assertIsNone(City3D.objects.none().extent3d()) check_extent3d(extent) self.assertIsNone(City3D.objects.none().aggregate(Extent3D('point'))['point__extent3d']) @ignore_warnings(category=RemovedInDjango20Warning) Loading tests/gis_tests/geoapp/feeds.py +2 −2 Original line number Diff line number Diff line Loading @@ -23,8 +23,8 @@ class TestGeoRSS2(TestGeoRSS1): def geometry(self, obj): # This should attach a <georss:box> element for the extent of # of the cities in the database. This tuple came from # calling `City.objects.extent()` -- we can't do that call here # because `extent` is not implemented for MySQL/Oracle. # calling `City.objects.aggregate(Extent())` -- we can't do that call # here because `Extent` is not implemented for MySQL/Oracle. return (-123.30, -41.32, 174.78, 48.46) def item_geometry(self, item): Loading Loading
django/contrib/gis/db/models/query.py +1 −97 Original line number Diff line number Diff line import warnings from django.contrib.gis.db.models import aggregates from django.contrib.gis.db.models.fields import ( GeometryField, LineStringField, PointField, get_srid_info, ) Loading @@ -15,9 +14,7 @@ from django.db.models.expressions import RawSQL from django.db.models.fields import Field from django.db.models.query import QuerySet from django.utils import six from django.utils.deprecation import ( RemovedInDjango20Warning, RemovedInDjango110Warning, ) from django.utils.deprecation import RemovedInDjango20Warning class GeoQuerySet(QuerySet): Loading Loading @@ -62,19 +59,6 @@ class GeoQuerySet(QuerySet): """ return self._geom_attribute('centroid', **kwargs) def collect(self, **kwargs): """ Performs an aggregate collect operation on the given geometry field. This is analogous to a union operation, but much faster because boundaries are not dissolved. """ warnings.warn( "The collect GeoQuerySet method is deprecated. Use the Collect() " "aggregate in an aggregate() or annotate() method.", RemovedInDjango110Warning, stacklevel=2 ) return self._spatial_aggregate(aggregates.Collect, **kwargs) def difference(self, geom, **kwargs): """ Returns the spatial difference of the geographic field in a `difference` Loading Loading @@ -108,31 +92,6 @@ class GeoQuerySet(QuerySet): """ return self._geom_attribute('envelope', **kwargs) def extent(self, **kwargs): """ Returns the extent (aggregate) of the features in the GeoQuerySet. The extent will be returned as a 4-tuple, consisting of (xmin, ymin, xmax, ymax). """ warnings.warn( "The extent GeoQuerySet method is deprecated. Use the Extent() " "aggregate in an aggregate() or annotate() method.", RemovedInDjango110Warning, stacklevel=2 ) return self._spatial_aggregate(aggregates.Extent, **kwargs) def extent3d(self, **kwargs): """ Returns the aggregate extent, in 3D, of the features in the GeoQuerySet. It is returned as a 6-tuple, comprising: (xmin, ymin, zmin, xmax, ymax, zmax). """ warnings.warn( "The extent3d GeoQuerySet method is deprecated. Use the Extent3D() " "aggregate in an aggregate() or annotate() method.", RemovedInDjango110Warning, stacklevel=2 ) return self._spatial_aggregate(aggregates.Extent3D, **kwargs) def force_rhr(self, **kwargs): """ Returns a modified version of the Polygon/MultiPolygon in which Loading Loading @@ -227,19 +186,6 @@ class GeoQuerySet(QuerySet): """ return self._distance_attribute('length', None, **kwargs) def make_line(self, **kwargs): """ Creates a linestring from all of the PointField geometries in the this GeoQuerySet and returns it. This is a spatial aggregate method, and thus returns a geometry rather than a GeoQuerySet. """ warnings.warn( "The make_line GeoQuerySet method is deprecated. Use the MakeLine() " "aggregate in an aggregate() or annotate() method.", RemovedInDjango110Warning, stacklevel=2 ) return self._spatial_aggregate(aggregates.MakeLine, geo_field_type=PointField, **kwargs) def mem_size(self, **kwargs): """ Returns the memory size (number of bytes) that the geometry field takes Loading Loading @@ -415,19 +361,6 @@ class GeoQuerySet(QuerySet): """ return self._geomset_attribute('union', geom, **kwargs) def unionagg(self, **kwargs): """ Performs an aggregate union on the given geometry field. Returns None if the GeoQuerySet is empty. The `tolerance` keyword is for Oracle backends only. """ warnings.warn( "The unionagg GeoQuerySet method is deprecated. Use the Union() " "aggregate in an aggregate() or annotate() method.", RemovedInDjango110Warning, stacklevel=2 ) return self._spatial_aggregate(aggregates.Union, **kwargs) # ### Private API -- Abstracted DRY routines. ### def _spatial_setup(self, att, desc=None, field_name=None, geo_field_type=None): """ Loading Loading @@ -462,35 +395,6 @@ class GeoQuerySet(QuerySet): return procedure_args, geo_field def _spatial_aggregate(self, aggregate, field_name=None, geo_field_type=None, tolerance=0.05): """ DRY routine for calling aggregate spatial stored procedures and returning their result to the caller of the function. """ # Getting the field the geographic aggregate will be called on. geo_field = self._geo_field(field_name) if not geo_field: raise TypeError('%s aggregate only available on GeometryFields.' % aggregate.name) # Checking if there are any geo field type limitations on this # aggregate (e.g. ST_Makeline only operates on PointFields). if geo_field_type is not None and not isinstance(geo_field, geo_field_type): raise TypeError('%s aggregate may only be called on %ss.' % (aggregate.name, geo_field_type.__name__)) # Getting the string expression of the field name, as this is the # argument taken by `Aggregate` objects. agg_col = field_name or geo_field.name # Adding any keyword parameters for the Aggregate object. Oracle backends # in particular need an additional `tolerance` parameter. agg_kwargs = {} if connections[self.db].ops.oracle: agg_kwargs['tolerance'] = tolerance # Calling the QuerySet.aggregate, and returning only the value of the aggregate. return self.aggregate(geoagg=aggregate(agg_col, **agg_kwargs))['geoagg'] def _spatial_attribute(self, att, settings, field_name=None, model_att=None): """ DRY routine for calling a spatial stored procedure on a geometry column Loading
docs/ref/contrib/gis/geoquerysets.txt +0 −66 Original line number Diff line number Diff line Loading @@ -1216,72 +1216,6 @@ Returns the number of points in the first linestring in the geometry field in a ``num_points`` attribute on each element of the ``GeoQuerySet``; otherwise sets with ``None``. Spatial Aggregates ================== Aggregate Methods ----------------- .. deprecated:: 1.8 Aggregate methods are now deprecated. Prefer using their function-based equivalents. ``collect`` ~~~~~~~~~~~ .. method:: GeoQuerySet.collect(**kwargs) .. deprecated:: 1.8 Use the :class:`Collect` aggregate instead. Shortcut for ``aggregate(Collect(<field>))``. ``extent`` ~~~~~~~~~~ .. method:: GeoQuerySet.extent(**kwargs) .. deprecated:: 1.8 Use the :class:`Extent` aggregate instead. Shortcut for ``aggregate(Extent(<field>))``. ``extent3d`` ~~~~~~~~~~~~ .. method:: GeoQuerySet.extent3d(**kwargs) .. deprecated:: 1.8 Use the :class:`Extent` aggregate instead. Shortcut for ``aggregate(Extent3D(<field>))``. ``make_line`` ~~~~~~~~~~~~~ .. method:: GeoQuerySet.make_line(**kwargs) .. deprecated:: 1.8 Use the :class:`MakeLine` aggregate instead. Shortcut for ``aggregate(MakeLine(<field>))``. ``unionagg`` ~~~~~~~~~~~~ .. method:: GeoQuerySet.unionagg(**kwargs) .. deprecated:: 1.8 Use the :class:`Union` aggregate instead. Shortcut for ``aggregate(Union(<field>))``. Aggregate Functions ------------------- Loading
docs/releases/1.2.txt +1 −2 Original line number Diff line number Diff line Loading @@ -358,8 +358,7 @@ Support for 3D geometry fields was added, and may be enabled by setting the :attr:`~django.contrib.gis.db.models.GeometryField.dim` keyword to 3 in your :class:`~django.contrib.gis.db.models.GeometryField`. The :class:`~django.contrib.gis.db.models.Extent3D` aggregate and :meth:`~django.contrib.gis.db.models.GeoQuerySet.extent3d` ``GeoQuerySet`` method were added as a part of this feature. and ``extent3d()`` ``GeoQuerySet`` method were added as a part of this feature. The following :class:`~django.contrib.gis.db.models.GeoQuerySet` methods are new in 1.2: Loading
tests/gis_tests/geo3d/tests.py +3 −9 Original line number Diff line number Diff line Loading @@ -12,9 +12,7 @@ from django.contrib.gis.gdal import HAS_GDAL from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon from django.test import TestCase, ignore_warnings, skipUnlessDBFeature from django.utils._os import upath from django.utils.deprecation import ( RemovedInDjango20Warning, RemovedInDjango110Warning, ) from django.utils.deprecation import RemovedInDjango20Warning from .models import ( City3D, Interstate2D, Interstate3D, InterstateProj2D, InterstateProj3D, Loading Loading @@ -217,7 +215,6 @@ class Geo3DTest(Geo3DLoadingHelper, TestCase): self.assertSetEqual({p.ewkt for p in ref_union}, {p.ewkt for p in union}) @skipUnlessDBFeature("supports_3d_functions") @ignore_warnings(category=RemovedInDjango110Warning) def test_extent(self): """ Testing the Extent3D aggregate for 3D models. Loading @@ -225,16 +222,13 @@ class Geo3DTest(Geo3DLoadingHelper, TestCase): self._load_city_data() # `SELECT ST_Extent3D(point) FROM geo3d_city3d;` ref_extent3d = (-123.305196, -41.315268, 14, 174.783117, 48.462611, 1433) extent1 = City3D.objects.aggregate(Extent3D('point'))['point__extent3d'] extent2 = City3D.objects.extent3d() extent = City3D.objects.aggregate(Extent3D('point'))['point__extent3d'] def check_extent3d(extent3d, tol=6): for ref_val, ext_val in zip(ref_extent3d, extent3d): self.assertAlmostEqual(ref_val, ext_val, tol) for e3d in [extent1, extent2]: check_extent3d(e3d) self.assertIsNone(City3D.objects.none().extent3d()) check_extent3d(extent) self.assertIsNone(City3D.objects.none().aggregate(Extent3D('point'))['point__extent3d']) @ignore_warnings(category=RemovedInDjango20Warning) Loading
tests/gis_tests/geoapp/feeds.py +2 −2 Original line number Diff line number Diff line Loading @@ -23,8 +23,8 @@ class TestGeoRSS2(TestGeoRSS1): def geometry(self, obj): # This should attach a <georss:box> element for the extent of # of the cities in the database. This tuple came from # calling `City.objects.extent()` -- we can't do that call here # because `extent` is not implemented for MySQL/Oracle. # calling `City.objects.aggregate(Extent())` -- we can't do that call # here because `Extent` is not implemented for MySQL/Oracle. return (-123.30, -41.32, 174.78, 48.46) def item_geometry(self, item): Loading