Fixed #25654 -- Added the GEOSGeometry.unary_union property.

This commit is contained in:
Sergey Fedoseev 2015-11-09 22:36:12 +05:00 committed by Tim Graham
parent 1e35dd1a05
commit 034dfbfc05
6 changed files with 37 additions and 0 deletions

View File

@ -621,6 +621,11 @@ class GEOSGeometry(GEOSBase, ListMixin):
""" """
return self._topology(capi.geos_symdifference(self.ptr, other.ptr)) return self._topology(capi.geos_symdifference(self.ptr, other.ptr))
@property
def unary_union(self):
"Return the union of all the elements of this geometry."
return self._topology(capi.geos_unary_union(self.ptr))
def union(self, other): def union(self, other):
"Returns a Geometry representing all the points in this Geometry and other." "Returns a Geometry representing all the points in this Geometry and other."
return self._topology(capi.geos_union(self.ptr, other.ptr)) return self._topology(capi.geos_union(self.ptr, other.ptr))

View File

@ -34,6 +34,7 @@ geos_symdifference = Topology('GEOSSymDifference', argtypes=[GEOM_PTR, GEOM_PTR]
geos_union = Topology('GEOSUnion', argtypes=[GEOM_PTR, GEOM_PTR]) geos_union = Topology('GEOSUnion', argtypes=[GEOM_PTR, GEOM_PTR])
geos_cascaded_union = GEOSFuncFactory('GEOSUnionCascaded', argtypes=[GEOM_PTR], restype=GEOM_PTR) geos_cascaded_union = GEOSFuncFactory('GEOSUnionCascaded', argtypes=[GEOM_PTR], restype=GEOM_PTR)
geos_unary_union = GEOSFuncFactory('GEOSUnaryUnion', argtypes=[GEOM_PTR], restype=GEOM_PTR)
# GEOSRelate returns a string, not a geometry. # GEOSRelate returns a string, not a geometry.
geos_relate = GEOSFuncFactory( geos_relate = GEOSFuncFactory(

View File

@ -497,6 +497,21 @@ geometry is a point.
Computes and returns a :class:`Point` guaranteed to be on the interior Computes and returns a :class:`Point` guaranteed to be on the interior
of this geometry. of this geometry.
.. attribute:: GEOSGeometry.unary_union
.. versionadded:: 1.10
Computes the union of all the elements of this geometry.
The result obeys the following contract:
* Unioning a set of :class:`LineString`\s has the effect of fully noding and
dissolving the linework.
* Unioning a set of :class:`Polygon`\s will always return a :class:`Polygon` or
:class:`MultiPolygon` geometry (unlike :meth:`GEOSGeometry.union`, which may
return geometries of lower dimension if a topology collapse occurs).
Other Properties & Methods Other Properties & Methods
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -64,6 +64,10 @@ Minor features
* :ref:`Distance lookups <distance-lookups>` now accept expressions as the * :ref:`Distance lookups <distance-lookups>` now accept expressions as the
distance value parameter. distance value parameter.
* The new :attr:`GEOSGeometry.unary_union
<django.contrib.gis.geos.GEOSGeometry.unary_union>` property computes the
union of all the elements of this geometry.
:mod:`django.contrib.messages` :mod:`django.contrib.messages`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -421,6 +421,7 @@ linebreaks
linebreaksbr linebreaksbr
linenumbers linenumbers
linestring linestring
linework
Livni Livni
ljust ljust
loaddata loaddata
@ -520,6 +521,7 @@ nestable
neuroscientist neuroscientist
newforms newforms
nginx nginx
noding
nonspatial nonspatial
nullable nullable
OAuth OAuth
@ -877,6 +879,7 @@ unicode
uninstall uninstall
uninstalling uninstalling
uninstalls uninstalls
unioning
uniterated uniterated
unittest unittest
unittests unittests

View File

@ -582,6 +582,15 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
a |= b # testing __ior__ a |= b # testing __ior__
self.assertEqual(u1, a) self.assertEqual(u1, a)
def test_unary_union(self):
"Testing unary_union."
for i in range(len(self.geometries.topology_geoms)):
a = fromstr(self.geometries.topology_geoms[i].wkt_a)
b = fromstr(self.geometries.topology_geoms[i].wkt_b)
u1 = fromstr(self.geometries.union_geoms[i].wkt)
u2 = GeometryCollection(a, b).unary_union
self.assertTrue(u1.equals(u2))
def test_difference(self): def test_difference(self):
"Testing difference()." "Testing difference()."
for i in range(len(self.geometries.topology_geoms)): for i in range(len(self.geometries.topology_geoms)):