From 9c1714234a8695a8c0838f2e5f650da043a52892 Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Sat, 15 Sep 2007 19:19:11 +0000 Subject: [PATCH] gis: Fixed #5434, GEOS `simplify()` may now preserve topologies via patch from rcoup. git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@6315 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/gis/geos/base.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/django/contrib/gis/geos/base.py b/django/contrib/gis/geos/base.py index b431ef15bf..8efd53dc83 100644 --- a/django/contrib/gis/geos/base.py +++ b/django/contrib/gis/geos/base.py @@ -496,13 +496,22 @@ class GEOSGeometry(object): "Computes an interior point of this Geometry." return self._unary_topology(lgeos.GEOSPointOnSurface) - def simplify(self, tolerance=0.0): + def simplify(self, tolerance=0.0, preserve_topology=False): """ Returns the Geometry, simplified using the Douglas-Peucker algorithm to the specified tolerance (higher tolerance => less points). If no tolerance provided, defaults to 0. + + By default, this function does not preserve topology - e.g. polygons can + be split, collapse to lines or disappear holes can be created or + disappear, and lines can cross. By specifying preserve_topology=True, + the result will have the same dimension and number of components as the + input. This is significantly slower. """ - return self._unary_topology(lgeos.GEOSSimplify, c_double(tolerance)) + if preserve_topology: + return self._unary_topology(lgeos.GEOSTopologyPreserveSimplify, c_double(tolerance)) + else: + return self._unary_topology(lgeos.GEOSSimplify, c_double(tolerance)) def relate(self, other): "Returns the DE-9IM intersection matrix for this Geometry and the other."