summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2021-09-24 10:15:23 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-09-27 09:58:28 +0200
commit4ffada36097ceccfd6f0d358217ac3c40d2a729c (patch)
tree314864f4c59f246d46ec4fd2b47d2d04ea7d85bb /django
parentfb05ca420da1341c0d39cf1f0e2fb659be836c92 (diff)
Fixed #33136 -- Added GEOSGeometry.make_valid() method.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/gis/geos/geometry.py11
-rw-r--r--django/contrib/gis/geos/prototypes/__init__.py6
-rw-r--r--django/contrib/gis/geos/prototypes/geom.py1
3 files changed, 14 insertions, 4 deletions
diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py
index bdb3868ac5..36f6895224 100644
--- a/django/contrib/gis/geos/geometry.py
+++ b/django/contrib/gis/geos/geometry.py
@@ -11,7 +11,7 @@ from django.contrib.gis.geos import prototypes as capi
from django.contrib.gis.geos.base import GEOSBase
from django.contrib.gis.geos.coordseq import GEOSCoordSeq
from django.contrib.gis.geos.error import GEOSException
-from django.contrib.gis.geos.libgeos import GEOM_PTR
+from django.contrib.gis.geos.libgeos import GEOM_PTR, geos_version_tuple
from django.contrib.gis.geos.mutable_list import ListMixin
from django.contrib.gis.geos.prepared import PreparedGeometry
from django.contrib.gis.geos.prototypes.io import (
@@ -219,6 +219,15 @@ class GEOSGeometryBase(GEOSBase):
"Convert this Geometry to normal form (or canonical form)."
capi.geos_normalize(self.ptr)
+ def make_valid(self):
+ """
+ Attempt to create a valid representation of a given invalid geometry
+ without losing any of the input vertices.
+ """
+ if geos_version_tuple() < (3, 8):
+ raise GEOSException('GEOSGeometry.make_valid() requires GEOS >= 3.8.0.')
+ return GEOSGeometry(capi.geos_makevalid(self.ptr), srid=self.srid)
+
# #### Unary predicates ####
@property
def empty(self):
diff --git a/django/contrib/gis/geos/prototypes/__init__.py b/django/contrib/gis/geos/prototypes/__init__.py
index 844ae4cda7..a79533fa14 100644
--- a/django/contrib/gis/geos/prototypes/__init__.py
+++ b/django/contrib/gis/geos/prototypes/__init__.py
@@ -12,9 +12,9 @@ from django.contrib.gis.geos.prototypes.coordseq import ( # NOQA
from django.contrib.gis.geos.prototypes.geom import ( # NOQA
create_collection, create_empty_polygon, create_linearring,
create_linestring, create_point, create_polygon, destroy_geom, geom_clone,
- geos_get_srid, geos_normalize, geos_set_srid, geos_type, geos_typeid,
- get_dims, get_extring, get_geomn, get_intring, get_nrings, get_num_coords,
- get_num_geoms,
+ geos_get_srid, geos_makevalid, geos_normalize, geos_set_srid, geos_type,
+ geos_typeid, get_dims, get_extring, get_geomn, get_intring, get_nrings,
+ get_num_coords, get_num_geoms,
)
from django.contrib.gis.geos.prototypes.misc import * # NOQA
from django.contrib.gis.geos.prototypes.predicates import ( # NOQA
diff --git a/django/contrib/gis/geos/prototypes/geom.py b/django/contrib/gis/geos/prototypes/geom.py
index a84f710900..4cd34504db 100644
--- a/django/contrib/gis/geos/prototypes/geom.py
+++ b/django/contrib/gis/geos/prototypes/geom.py
@@ -44,6 +44,7 @@ class StringFromGeom(GEOSFuncFactory):
# ### ctypes prototypes ###
# The GEOS geometry type, typeid, num_coordinates and number of geometries
+geos_makevalid = GeomOutput('GEOSMakeValid', argtypes=[GEOM_PTR])
geos_normalize = IntFromGeom('GEOSNormalize')
geos_type = StringFromGeom('GEOSGeomType')
geos_typeid = IntFromGeom('GEOSGeomTypeId')