View Ticket
Not logged in
Ticket Hash: 08771f948e9cc557eecc02b4e97b4864dece1b92
Title: ST_Simplify doesn't remove first vertex
Status: Closed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Resolution: Works_As_Designed
Last Modified: 2022-03-07 09:07:01
Version Found In: 4.3.0
User Comments:
anonymous added on 2021-10-01 17:07:07:

ST_Simplify never removes first vertex of the polygon.

Example: Vertex (0, 0) is not removed even though it is collinear with (-1, 0) and (1, 0)

sqlite> select st_astext(st_simplify(st_geomfromtext('POLYGON((0 0, 1 0, 0 1, -1 0, 0 0))'), 0.1));
POLYGON((0 0, -1 0, 0 1, 1 0, 0 0))

OTOH with (0, 0) in the middle of the ring the simplification is successful

sqlite> select st_astext(st_simplify(st_geomfromtext('POLYGON((-1 0, 0 0, 1 0, 0 1, -1 0))'), 0.1));
POLYGON((-1 0, 0 1, 1 0, -1 0))

This is problematic for me because I want to remove duplicated geometries with

ST_Equals(ST_Simplify(a.geom1, 0.1), ST_Simplify(b.geom, 0.1)) = 1

and it fails for such edge cases.


anonymous added on 2021-10-20 15:31:28:

PostGIS returns also POLYGON((0 0,1 0,0 1,-1 0,0 0)). ST_Simplify is doing Ramer-Douglas-Peucker https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm that seems to be made to keep the start and end points untouched.

For just this geometry the following PostGIS query could make you happy but st_normalize does not always change the place of the first point.

select st_astext(ST_Simplify(st_normalize(st_geomfromtext('POLYGON((0 0, 1 0, 0 1, -1 0, 0 0))')),0.01));

I believe that ST_Simplify will not be changed but your edge case is interesting one. Perhaps you must have two rounds, one with original polygon and another with off-by-one re-ordered vertices.


sandro added on 2022-03-07 09:07:01:

just two simple remarks:

  1. as already noted ST_Simplify is based on the Douglas-Peucker algorithm, and this one explicitly forbids to remove the first/last vertices of the linestring or ring to be simplified.

  2. ST_Simplify just calls GEOSSimplify(), an API defined by the GEOS library (the same used by PostGIS and many others)

if you think there is something wrong in the GEOSSimplify() implementation you should fill a ticket on the GEOS own bug tracker