Simplify the straight sections of (multi)Linestring in PostgreSQL/PostGIS leaving the curved sections untouched
This is easily achievable by using ST_SimplifyVW which is available in PostGIS from version 2.2.0 If you chose small tolerance, then points forming straight (or nearly straight) lines will be removed. As a side-effect, it will remove also points forming small triangles, if their area will be within a specified tolerance, so be aware of it...
Use ST_SetEffectiveArea
in conjunction with ST_FilterByM
on the result of ST_LineMerge
, e.g.:
SELECT ST_AsText(
ST_FilterByM(
ST_SetEffectiveArea(
ST_LineMerge('MULTILINESTRING((0 0, 0 1), (0 1, 0 2), (0 2, 0 3), (0 3, 0 4), (0 4, 1 4), (1 4, 2 4), (2 4, 3 4))'::GEOMETRY)
),
0.0001
)
)
;
SELECT ST_AsText(
ST_FilterByM(
ST_SetEffectiveArea(
ST_Buffer('POINT(0 0)'::GEOMETRY, 0.1)
),
0.0001
)
)
;