27

I was wondering if there is a way to create center lines from polygons in QGIS?

I have a polygon layer, but ideally need the centerlines as a separate file.

Example

5
  • I've just uploaded a picture of the polygons
    – Alan Carr
    Commented Sep 20, 2012 at 10:39
  • Where, in the example image, would the 'centrelines' fall? Could you update the image showing the desired lines in a different colour, perhaps?
    – Simbamangu
    Commented Sep 20, 2012 at 10:55
  • Just directly down the middle of all polygons. The final outcome we need would be to just find the length of the whole thing (assuming the polygons were lines) so it's not even essential to get centrelines.
    – Alan Carr
    Commented Sep 20, 2012 at 11:09
  • 1
    The HCMGIS plugin claims to create polygon centerlines as one of its Spatial Processing features. It didn't work very well for me, but it might be worth a try.
    – csk
    Commented Jun 25, 2019 at 18:40
  • The Centerline tool in the Geometric Attributes plugin works pretty well for me. I had to buffer with a small negative number, as per the author's recommendations: github.com/BjornNyberg/Geometric-Attributes-Toolbox/blob/master/…. Then I had to densify as some of my polygons (straight roads) had insufficient nodes for the tool to work properly.
    – blackthorn
    Commented Dec 16, 2020 at 10:53

6 Answers 6

12

I've been working on implementing the model depicted in @RajGovind's answer to Creating Centrelines from Road Polygons/Casings? which is quite close to what @geogeek described in his answer here in this thread.

You can download the model from Github https://raw.githubusercontent.com/anitagraser/QGIS-Processing-tools/master/2.12/models/polygon_to_centerline.model

enter image description here

2
  • I've tried this model and it works, but I've been unable to figure out a simple way to keep the long center lines but removing the little side lines, since each of the side lines are composed of many smaller features, and the main centerline is also composed of many smaller line features.
    – Jan
    Commented Sep 4, 2016 at 19:41
  • @Jan please post this follow-up question in a new thread so more people will see it.
    – underdark
    Commented Sep 5, 2016 at 15:52
10

you can try This algorithme:

get vertices from the polygons(poly_vertex).
-make voronoi using (poly_vertex) as input the result could be called(poly_voronoi).
-get lines from (poly_voronoi) => (poly_voronoi_lines).
-get the originale polygon contour (polygon_lines).
-remove (poly_voronoi_lines) touching  (polygon_lines) the result is supposed to be the center lines , but you may need further clean up.

i don't know how it could be implemented on Qgis

i wish it could help

2
8

there is a good tool with the name of ET GeoWizards 10.2 for Esri products, but i dont know whether it is a good solution or not...

you can get some info from here

centerLines

beside this in grass you can check out r.thin function for basic use..

r.thin - Thins non-zero cells that denote linear features in a raster map layer.

rthin i hope it helps you...

1
  • r.thin did it, on an irregular polygon, not street lines
    – Elio Diaz
    Commented Sep 30, 2020 at 21:11
8

A few days ago, I was researching a more productive way to extract centerlines and I came across this QGIS plugin: Geo Simplification (https://plugins.qgis.org/plugins/geo_sim_processing/)

At https://github.com/NRCan/geo_sim_processing you can get more information about the algorithm implemented in the plugin to extract centerlines (Chordal Axis).

I tested it in a few cases and got good results. I think is a good option.

Here you can check a result obtained with the plugin. enter image description here

I hope this can help you guys!

The option "correction" creates a real centre-line while omitting it creates multiples lines from each vertex towards the center similar to a Voronoi polygon.

2
  • 1
    Great plugin. But, in some of my cases it was only partly making the center lines (for some polygons yes, and for some not).
    – Josip G
    Commented Aug 26, 2023 at 9:17
  • 1
    I found out why. "Feature ID 1 could not be divided into triangular components." So, with a bit of Simplification and manual polygon cleaning it turned out to be OK.
    – Josip G
    Commented Aug 26, 2023 at 10:22
3

just find the length of the whole thing

How exactly should be the result? An approximation is perimeter divided by 2.

To get a better result: You can manually measure some polygons.Then determine the difference between the measurement and perimeter divided by 2. Apply this correctionfactor to the whole datset.

1

The GRASS Tool v.voronoi.skeleton in QGIS does what you are looking for. The algorythm works similarly to the solution posted here: Creating centerline of river in QGIS?

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.