ST_Simplify

更新时间:
复制 MD 格式

Returns a simplified geometry using the Douglas-Peucker algorithm. Use this function to reduce vertex count for map rendering or storage optimization.

Syntax

geometry ST_Simplify(geometry geomA, float tolerance, boolean preserveCollapsed);

Parameters

ParameterTypeDescription
geomAgeometryThe input geometry to simplify.
tolerancefloatThe simplification threshold.
preserveCollapsedbooleanWhen true, retains small geometries that would otherwise disappear because they are smaller than the tolerance value.

Usage notes

ST_Simplify accepts any geometry type, including GeometryCollection. The function processes each element individually, so it works with collections. Simplification operations are supported on MultiLine objects, MultiPolygon objects, and MultiPoint objects.

ST_Simplify may return invalid geometry or cause a geometry to lose simplicity, because it does not guarantee topological correctness. To preserve topology, use ST_SimplifyPreserveTopology instead.

When to use preserveCollapsed

When a geometry's scale is much smaller than the tolerance value, simplification can collapse it and the geometry object may disappear. Set preserveCollapsed to true to retain these small geometries.

This is useful in rendering engines where eliminating small geometries leaves visible gaps on a map.

Examples

The following examples use a LINESTRING geometry and compare results across different tolerance values.

Compare simplification at tolerance 0.25 and 0.5:

SELECT g,
       ST_Simplify(g, 0.25),
       ST_Simplify(g, 0.5)
FROM (
  SELECT 'LINESTRING(0 0,2 2,3 1,3.5 1.5,5 0,5.25 0.25,5.5 0)'::geometry AS g
) AS t;

123

Related functions