ST_ChaikinSmoothing

更新时间:
复制 MD 格式

Returns a smoothed version of a geometry using the Chaikin algorithm.

Syntax

geometry ST_ChaikinSmoothing(geometry geom, integer nIterations = 1, boolean preserveEndPoints = false);

Parameters

ParameterDescription
geomThe input geometry to smooth.
nIterationsNumber of smoothing iterations. Maximum value: 5. Default value: 1.
preserveEndPointsSpecifies whether to preserve the endpoints of the input geometry. Default value: false. Takes effect only when the input is a polygon.

How it works

Each iteration doubles the number of vertices in the geometry: a new vertex is placed at one-quarter of the distance along each adjacent line segment, and the original vertex is removed. New vertices are interpolated across all dimensions of the input geometry, including z and m.

Each iteration doubles the vertex count, so the output geometry can have significantly more vertices than the input. To reduce the number of vertices, pass the result to ST_Simplify (Douglas-Peucker algorithm) or ST_SimplifyVW (Visvalingam-Whyatt algorithm).

Examples

The following query applies nIterations = 1 and nIterations = 5 to the same line string to compare the smoothing effect:

select g,ST_ChaikinSmoothing(g,1),
             ST_ChaikinSmoothing(g,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