Skip to content
🎉 Apache Sedona 1.8.1 is now available! Check out the new features and improvements.

ST_RemoveRepeatedPoints

Introduction: This function eliminates consecutive duplicate points within a geometry, preserving endpoints of LineStrings. It operates on (Multi)LineStrings, (Multi)Polygons, and MultiPoints, processing GeometryCollection elements individually. When an optional 'tolerance' value is provided, vertices within that distance are also considered duplicates.

Format:

ST_RemoveRepeatedPoints(geom: Geometry, tolerance: Double)

ST_RemoveRepeatedPoints(geom: Geometry)

SQL Example:

SELECT ST_RemoveRepeatedPoints(
        ST_GeomFromWKT('MULTIPOINT ((20 20), (10 10), (30 30), (40 40), (20 20), (30 30), (40 40))')
       )

Output:

MULTIPOINT ((20 20), (10 10), (30 30), (40 40))

SQL Example:

SELECT ST_RemoveRepeatedPoints(
        ST_GeomFromWKT('LINESTRING (20 20, 10 10, 30 30, 40 40, 20 20, 30 30, 40 40)')
       )

Output:

LINESTRING (20 20, 10 10, 30 30, 40 40, 20 20, 30 30, 40 40)

SQL Example: Each geometry within a collection is processed independently.

ST_RemoveRepeatedPoints(
        ST_GeomFromWKT('GEOMETRYCOLLECTION (POINT (10 10), POINT(10 10), LINESTRING (20 20, 20 20, 30 30, 30 30), MULTIPOINT ((80 80), (90 90), (90 90), (100 100)))')
    )

Output:

GEOMETRYCOLLECTION (POINT (10 10), POINT (10 10), LINESTRING (20 20, 30 30), MULTIPOINT ((80 80), (90 90), (100 100)))

SQL Example: Elimination of repeated points within a specified distance tolerance.

SELECT ST_RemoveRepeatedPoints(
        ST_GeomFromWKT('LINESTRING (20 20, 10 10, 30 30, 40 40, 20 20, 30 30, 40 40)'),
        20
       )

Output:

LINESTRING (20 20, 40 40, 20 20, 40 40)