Fixed #27550 -- Allowed GEOSGeometry.normalize() to return a normalized clone.
This commit is contained in:
parent
d27e6b233f
commit
76af861356
|
@ -222,8 +222,16 @@ class GEOSGeometryBase(GEOSBase):
|
||||||
"Return the dimension of this Geometry (0=point, 1=line, 2=surface)."
|
"Return the dimension of this Geometry (0=point, 1=line, 2=surface)."
|
||||||
return capi.get_dims(self.ptr)
|
return capi.get_dims(self.ptr)
|
||||||
|
|
||||||
def normalize(self):
|
def normalize(self, clone=False):
|
||||||
"Convert this Geometry to normal form (or canonical form)."
|
"""
|
||||||
|
Convert this Geometry to normal form (or canonical form).
|
||||||
|
If the `clone` keyword is set, then the geometry is not modified and a
|
||||||
|
normalized clone of the geometry is returned instead.
|
||||||
|
"""
|
||||||
|
if clone:
|
||||||
|
clone = self.clone()
|
||||||
|
capi.geos_normalize(clone.ptr)
|
||||||
|
return clone
|
||||||
capi.geos_normalize(self.ptr)
|
capi.geos_normalize(self.ptr)
|
||||||
|
|
||||||
def make_valid(self):
|
def make_valid(self):
|
||||||
|
|
|
@ -665,9 +665,11 @@ Other Properties & Methods
|
||||||
:class:`~django.contrib.gis.db.models.functions.MakeValid` database
|
:class:`~django.contrib.gis.db.models.functions.MakeValid` database
|
||||||
function. Requires GEOS 3.8.
|
function. Requires GEOS 3.8.
|
||||||
|
|
||||||
.. method:: GEOSGeometry.normalize()
|
.. method:: GEOSGeometry.normalize(clone=False)
|
||||||
|
|
||||||
Converts this geometry to canonical form::
|
Converts this geometry to canonical form. If the ``clone`` keyword is set,
|
||||||
|
then the geometry is not modified and a normalized clone of the geometry is
|
||||||
|
returned instead::
|
||||||
|
|
||||||
>>> g = MultiPoint(Point(0, 0), Point(2, 2), Point(1, 1))
|
>>> g = MultiPoint(Point(0, 0), Point(2, 2), Point(1, 1))
|
||||||
>>> print(g)
|
>>> print(g)
|
||||||
|
@ -676,6 +678,10 @@ Other Properties & Methods
|
||||||
>>> print(g)
|
>>> print(g)
|
||||||
MULTIPOINT (2 2, 1 1, 0 0)
|
MULTIPOINT (2 2, 1 1, 0 0)
|
||||||
|
|
||||||
|
.. versionchanged:: 4.1
|
||||||
|
|
||||||
|
The ``clone`` argument was added.
|
||||||
|
|
||||||
``Point``
|
``Point``
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,9 @@ Minor features
|
||||||
* The new :meth:`.GEOSGeometry.make_valid()` method allows converting invalid
|
* The new :meth:`.GEOSGeometry.make_valid()` method allows converting invalid
|
||||||
geometries to valid ones.
|
geometries to valid ones.
|
||||||
|
|
||||||
|
* The new ``clone`` argument for :meth:`.GEOSGeometry.normalize` allows
|
||||||
|
creating a normalized clone of the geometry.
|
||||||
|
|
||||||
:mod:`django.contrib.messages`
|
:mod:`django.contrib.messages`
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -1528,11 +1528,17 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
||||||
self.assertEqual(GEOSGeometry("POINT(1.0e-1 1.0e+1)"), Point(0.1, 10))
|
self.assertEqual(GEOSGeometry("POINT(1.0e-1 1.0e+1)"), Point(0.1, 10))
|
||||||
|
|
||||||
def test_normalize(self):
|
def test_normalize(self):
|
||||||
g = MultiPoint(Point(0, 0), Point(2, 2), Point(1, 1))
|
multipoint = MultiPoint(Point(0, 0), Point(2, 2), Point(1, 1))
|
||||||
self.assertIsNone(g.normalize())
|
normalized = MultiPoint(Point(2, 2), Point(1, 1), Point(0, 0))
|
||||||
self.assertTrue(
|
# Geometry is normalized in-place and nothing is returned.
|
||||||
g.equals_exact(MultiPoint(Point(2, 2), Point(1, 1), Point(0, 0)))
|
multipoint_1 = multipoint.clone()
|
||||||
)
|
self.assertIsNone(multipoint_1.normalize())
|
||||||
|
self.assertEqual(multipoint_1, normalized)
|
||||||
|
# If the `clone` keyword is set, then the geometry is not modified and
|
||||||
|
# a normalized clone of the geometry is returned instead.
|
||||||
|
multipoint_2 = multipoint.normalize(clone=True)
|
||||||
|
self.assertEqual(multipoint_2, normalized)
|
||||||
|
self.assertNotEqual(multipoint, normalized)
|
||||||
|
|
||||||
@skipIf(geos_version_tuple() < (3, 8), "GEOS >= 3.8.0 is required")
|
@skipIf(geos_version_tuple() < (3, 8), "GEOS >= 3.8.0 is required")
|
||||||
def test_make_valid(self):
|
def test_make_valid(self):
|
||||||
|
|
Loading…
Reference in New Issue