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(way,300):

enter image description here

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".


1 Answer 1


"Simplifying" is making geometry smaller - fewer vertexes. Maybe you want smoothing instead?

PostGIS 2.5 will have Chaikin smoothing: https://postgis.net/docs/manual-dev/ST_ChaikinSmoothing.html

  • Heh, what is the title of my question? :) Apr 11, 2018 at 3:53
  • @SteveBennett, did you take a look at ST_ChaikinSmoothing? I guess that will do what you want. But probably you want to simplify the result since each iteration doubles the number of vertex points. Apr 18, 2018 at 13:15
  • Well, I posted my question almost 5 years ago :) I don't have this same need right now. Still keen to have a look at some point. Apr 19, 2018 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.