karakulj
karakulj

Reputation: 123

Algorithm for smoothing the edges of a polygon

I use Node.js and Concave hull algorithm for isolating UK postcode sectors. This is what I get for now: enter image description here

So now, I need to smooth boundaries to look like this: enter image description here

Does anyone have any idea which algorithm should I use?

Upvotes: 2

Views: 3370

Answers (2)

nicholaswmin
nicholaswmin

Reputation: 22959

There are at least 2 approaches to this:

  • Curve fitting algorithms(best for your use case)
  • Rammer-Douglas-Peucker algorithm (simpler to implement)

The Rammer-Douglas-Peucker algorithm reduces the node count of a polygon - this will not smooth it in the sense that it will make it curvy, it will simply reduce the nodes(roughness), whilst struggling to keep the polygon in it's original shape as much as possible

Although what you are, most probably, after is a Curve fitting algorithm through a series of points.

See this answer I've made (and the answer above, which is more descriptive) for solutions to this.

Upvotes: 1

Ciro Costa
Ciro Costa

Reputation: 2585

There seems to be a lots of ways of doing this. I'm inclined to cite some kind of bezier interpolation (http://www.antigrain.com/research/bezier_interpolation/).

@amit gave another great clue about how to solve the problem, splines are actually pretty useful for smoothing polygons. See the related question: https://gis.stackexchange.com/questions/24827/how-to-smooth-the-polygons-in-a-contour-map

Hope it helps!

Upvotes: 1

Related Questions