Categories:

Geospatial Functions

# ST_SIMPLIFY¶

Given an input GEOGRAPHY object that represents a line or polygon, returns a simpler approximation of the object. The function uses the Douglas–Peucker algorithm to identify and remove selected vertices, resulting in a simpler object that has fewer vertices.

For example, if the input object is a polygon with 50 vertices, ST_SIMPLIFY can return a simpler polygon with only 20 of those vertices.

When simplifying an object, the function removes a vertex only if the distance between that vertex and the edge resulting from the removal of that vertex is within the specified tolerance.

## Syntax¶

ST_SIMPLIFY( <geography_expression>, <tolerance> [ , <preserve_collapsed> ] )


## Arguments¶

Required:

geography_expression

The GEOGRAPHY object to simplify.

Depending on the type of the GEOGRAPHY object, ST_SIMPLIFY has the following effect:

Type of Object

Effect of ST_SIMPLIFY

LineString, MultiLineString, Polygon, or MultiPolygon

ST_SIMPLIFY applies the simplification algorithm

Point or MultiPoint

ST_SIMPLIFY has no effect.

GeometryCollection or FeatureCollection

ST_SIMPLIFY applies the simplification algorithm to each object in the collection.

tolerance

The maximum distance in meters between a vertex and the edge resulting from the removal of the vertex. If the distance exceeds this tolerance for a vertex, ST_SIMPLIFY keeps that vertex in the simplified object.

Optional:

preserve_collapsed

If TRUE, retains objects that would otherwise be too small given the tolerance.

For example, when preserve_collapsed is FALSE and tolerance is 10 (meters), a 1m long line is reduced to a point in the simplified object. When preserve_collapsed is TRUE, the line is preserved in the simplified object.

Default: FALSE.

## Returns¶

The function returns a value of type GEOGRAPHY.

## Examples¶

The examples in this section display output in WKT format:

alter session set GEOGRAPHY_OUTPUT_FORMAT='WKT';


The following example returns a simplified LineString that has fewer vertices than the original LineString. In the simplified object, a vertex is omitted if the distance between the vertex and the edge that replaces the vertex is less than 1000 meters.

SELECT ST_SIMPLIFY(
TO_GEOGRAPHY('LINESTRING(-122.306067 37.55412, -122.32328 37.561801, -122.325879 37.586852)'),
1000);
+----------------------------------------------------------------------------------------------------+
| ST_SIMPLIFY(                                                                                       |
|     TO_GEOGRAPHY('LINESTRING(-122.306067 37.55412, -122.32328 37.561801, -122.325879 37.586852)'), |
|     1000)                                                                                          |
|----------------------------------------------------------------------------------------------------|
| LINESTRING(-122.306067 37.55412,-122.325879 37.586852)                                             |
+----------------------------------------------------------------------------------------------------+