diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py index 4649a895a0..0f27d2bcf9 100644 --- a/django/contrib/gis/geos/collections.py +++ b/django/contrib/gis/geos/collections.py @@ -3,6 +3,7 @@ GeometryCollection, MultiPoint, MultiLineString, and MultiPolygon """ import json +import warnings from ctypes import byref, c_int, c_uint from django.contrib.gis.geos import prototypes as capi @@ -13,6 +14,7 @@ from django.contrib.gis.geos.libgeos import get_pointer_arr from django.contrib.gis.geos.linestring import LinearRing, LineString from django.contrib.gis.geos.point import Point from django.contrib.gis.geos.polygon import Polygon +from django.utils.deprecation import RemovedInDjango20Warning from django.utils.six.moves import range @@ -135,6 +137,10 @@ class MultiPolygon(GeometryCollection): @property def cascaded_union(self): "Returns a cascaded union of this MultiPolygon." + warnings.warn( + "`cascaded_union` is deprecated, use the `unary_union` property instead.", + RemovedInDjango20Warning, 2 + ) return GEOSGeometry(capi.geos_cascaded_union(self.ptr), self.srid) # Setting the allowed types here since GeometryCollection is defined before diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 2b21b98179..6a312dc925 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -121,6 +121,9 @@ details on these changes. * The ``get_coords()`` and ``set_coords()`` methods of ``django.contrib.gis.geos.Point`` will be removed. +* The ``cascaded_union`` property of ``django.contrib.gis.geos.MultiPolygon`` + will be removed. + .. _deprecation-removed-in-1.10: 1.10 diff --git a/docs/ref/contrib/gis/geos.txt b/docs/ref/contrib/gis/geos.txt index abe22aad2f..8896ac0a30 100644 --- a/docs/ref/contrib/gis/geos.txt +++ b/docs/ref/contrib/gis/geos.txt @@ -746,6 +746,10 @@ Geometry Collections .. attribute:: cascaded_union + .. deprecated:: 1.10 + + Use the :attr:`GEOSGeometry.unary_union` property instead. + Returns a :class:`Polygon` that is the union of all of the component polygons in this collection. The algorithm employed is significantly more efficient (faster) than trying to union the geometries together diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt index 1c8b0b072d..33039eb73f 100644 --- a/docs/releases/1.10.txt +++ b/docs/releases/1.10.txt @@ -361,6 +361,10 @@ This prevents confusion about an assignment resulting in an implicit save. :class:`~django.contrib.gis.geos.Point` are deprecated in favor of the ``tuple`` property. +* The ``cascaded_union`` property of + :class:`~django.contrib.gis.geos.MultiPolygon` is deprecated in favor of the + :attr:`~django.contrib.gis.geos.GEOSGeometry.unary_union` property. + Miscellaneous ~~~~~~~~~~~~~ diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index 33cc7dea4a..da9db06c33 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -1203,3 +1203,9 @@ class GEOSTest(SimpleTestCase, TestDataMixin): p.set_coords((3, 2, 1)) self.assertEqual(p.get_coords(), (3, 2, 1)) + + @ignore_warnings(category=RemovedInDjango20Warning) + def test_deprecated_cascaded_union(self): + for geom in self.geometries.multipolygons: + mpoly = GEOSGeometry(geom.wkt) + self.assertEqual(mpoly.cascaded_union, mpoly.unary_union)