The SE_Generalize() function

The SE_Generalize() function reduces the number of vertices in an ST_LineString, ST_MultiLineString, ST_Polygon, or ST_MultiPolygon while preserving the general character of the geometric shape.

Syntax

SE_Generalize (g1 ST_Geometry, threshold float)

The value of the threshold argument must be small enough compared to the size of the object that the function can return a generalized shape.

Usage

This function uses the Douglas-Peucker line-simplification algorithm. The vertex sequence of the input geometry is recursively subdivided until a run of vertices can be replaced by a straight-line segment. No vertex in that iteration can deviate from the straight line by more than the threshold.

Z values, if present, are not considered when a set of vertices are simplified.

Figure 1: Geometries resulting from use of SE_Generalize()

This graphic shows a line, a polygon, and a multiline that each has fewer vertices after SE_Generalize() is used on it.

Return type

ST_Geometry, unless the input geometry is an ST_Point, ST_MultiPoint, or an empty geometry of any subtype, in which case this function returns NULL.

If the function returns error USE21, the value of the threshold argument is too large.

Example

The following statements create a table and a linestring that has multiple vertices:

CREATE TABLE jagged_lines(line ST_LineString);

INSERT INTO jagged_lines VALUES(
   "0 linestring(10 10, 20 20, 20 18, 30 30, 30 28, 40 40)"
);

The following example includes a small threshold value and results in no vertices being removed:

SELECT SE_Generalize(line, 0.5) FROM jagged_lines;

(expression)  0 LINESTRING (10 10, 20 20, 20 18, 30 30, 30 28, 40 40)

The following example includes a larger threshold value and results in some vertices being removed:

SELECT SE_Generalize(line, 2) FROM jagged_lines;

(expression)  0 LINESTRING (10 10, 40 40)