Skip to main content

ST_SimplifyPreserveTopology

Simplifies a geometry while preserving topological validity.

Syntax

ST_SimplifyPreserveTopology(geometry, tolerance)

Parameters

ParameterTypeDescription
geometryGeometryInput geometry
toleranceFloat64Distance tolerance for simplification

Returns

TypeDescription
Binary (WKB)Simplified geometry as WKB with geoarrow.wkb metadata

Examples

Safe Simplification

SELECT ST_SimplifyPreserveTopology(
ST_GeomFromText('POLYGON((0 0, 1 0, 1 0.1, 2 0, 2 2, 0 2, 0 0))'),
0.2
);
-- Returns simplified polygon that remains valid

Simplify Complex Coastlines

SELECT id, ST_SimplifyPreserveTopology(geom, 0.001) as simplified
FROM coastlines;

Ensure Validity After Simplification

SELECT id,
ST_IsValid(ST_Simplify(geom, 0.1)) as simple_valid,
ST_IsValid(ST_SimplifyPreserveTopology(geom, 0.1)) as topo_valid
FROM parcels;
-- topo_valid is always true

Progressive Simplification

SELECT
ST_NumPoints(geom) as original,
ST_NumPoints(ST_SimplifyPreserveTopology(geom, 0.001)) as low,
ST_NumPoints(ST_SimplifyPreserveTopology(geom, 0.01)) as medium,
ST_NumPoints(ST_SimplifyPreserveTopology(geom, 0.1)) as high
FROM complex_features;

Notes

  • Guaranteed to produce valid output from valid input
  • May remove fewer points than ST_Simplify to maintain validity
  • Prevents self-intersections and ring collapses
  • Slightly slower than ST_Simplify due to validity checks
  • Preferred for production use where validity is important

See Also