Returns a simplified and valid representation of a geometry object, using the Douglas-Peucker algorithm.
Syntax
geometry ST_SimplifyPreserveTopology(geometry geomA, float tolerance)Parameters
| Parameter | Description |
|---|---|
geomA | The geometry object to simplify. |
tolerance | The tolerance that you want to specify. |
Description
ST_SimplifyPreserveTopology applies the Douglas-Peucker simplification algorithm to a geometry object while guaranteeing a valid result.
Supported geometry types
Simplification operates on MultiLine, MultiPolygon, and MultiPoint objects. For GeometryCollection inputs, each geometry in the collection is simplified individually.
Unlike ST_Simplify, this function never returns an invalid derived geometry object, particularly for polygon inputs.
Examples
The following example compares the output of ST_SimplifyPreserveTopology and ST_Simplify on a self-intersecting polygon. ST_SimplifyPreserveTopology produces a valid polygon, while ST_Simplify returns an empty result because the simplified geometry would be invalid.
SELECT ST_ASText(ST_SimplifyPreserveTopology(g,1)) AS PreserveTopology,
ST_ASText(ST_Simplify(g,1)) AS Normal
FROM (SELECT 'POLYGON((0 0,1 0,0 1,1 1,0 0))'::geometry AS g) AS t;Output:
preservetopology | normal
----------------------------+--------
POLYGON((0 0,1 0,1 1,0 0)) |
(1 row)