3

I'm trying to get a centreline representation for some polygon output from OSM but having tried the approach in this post (Skeletonize vectors in QGIS/Python) I'm getting very odd results. Here's the polygon, the output from and the 'centreline' given by v.voronoi.skeleton with the smoothness set to 0.01.

smooth line many sections from v.voronoi.skeleton

You can see this has resulted in a lot of points. If I don't set the smoothness that low I end up with lots of jagged sections that aren't oriented in the direction of the line. jagged sections from v.voronoi.skeleton - defaults

What is the recommended approach to get to a final output that is like the following with right angles and points merged into longer line sections?

desired output

I'm trying to do this programmatically for x number of polygons.

EDIT: I've found using 'Simplify' and tweaking some of the settings can give close to the desired result, although orientation of the final line can be off.

1 Answer 1

1

As you are looking for a programatical solution... you could check out pygeoops.centerline. It also uses voronoi polygons as a basis to create the centerline, but also removes short branches, simplifies the result,... to get a "clean" result.

Sample script:

import pygeoops
import shapely

polygon = shapely.from_wkt("POLYGON ((0 0, 0 8, -2 10, 4 10, 2 8, 2 2, 10 2, 10 0, 0 0))")
centerline = pygeoops.centerline(polygon)

Result:

enter image description here

Disclaimer: I'm the developer of pygeoops

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.