I'm trying to automatically generate paths to place labels on that follow the shape of rivers, 4wd tracks and other very windy lines. At first I thought the
st_simplify() function was the answer, but it basically has exactly the opposite goal. Here's a result of
st_simplify() is trying to preserve the maximum amount of information from the underlying geometry, resulting in a very spiky line. What I'm looking for is a rough approximation of the line - something that would kind of pass down the center, without actually hitting any of the corner points.
The ultimate goal is to get more labels rendered in TileMill, without having to increase the
text-max-char-angle-delta setting, which looks pretty bad.
Is there a way to achieve this? I'm looking for a script or function to call - not just an algorithm to attempt to implement.
(OpenStreetMap data in PostGIS, rendered using TileMill. Happy to pre-process - performance is not a big concern.)
Also, note the difference from this question - I don't want "a smoother line of roughly the same significance to a human interpreter", I want "a smoother line roughly in the centre of the old line".