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

Taras
  • 32,823
  • 4
  • 66
  • 137
Alan Carr
  • 2,475
  • 6
  • 28
  • 44
  • I've just uploaded a picture of the polygons – Alan Carr Sep 20 '12 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 Sep 20 '12 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 Sep 20 '12 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 Jun 25 '19 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: https://github.com/BjornNyberg/Geometric-Attributes-Toolbox/blob/master/Datasets/README.pdf. Then I had to densify as some of my polygons (straight roads) had insufficient nodes for the tool to work properly. – blackthorn Dec 16 '20 at 10:53

6 Answers6

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

underdark
  • 84,148
  • 21
  • 231
  • 413
  • 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 Sep 04 '16 at 19:41
  • @Jan please post this follow-up question in a new thread so more people will see it. – underdark Sep 05 '16 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

geogeek
  • 4,566
  • 5
  • 35
  • 79
  • What other programs can you do this on. I can get access to MapInfo and Arc if neccessary – Alan Carr Sep 20 '12 at 11:35
  • this algorithme, will work surely in Arcgis and it could work too in Qgis using Voronoi polygons http://gis.stackexchange.com/questions/6971/thiessen-polygons-in-qgis – geogeek Sep 20 '12 at 11:39
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...

urcm
  • 22,533
  • 4
  • 57
  • 109
7

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.

user3386170
  • 1,957
  • 1
  • 28
  • 53
lcoandrade
  • 770
  • 5
  • 9
  • 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 Aug 26 '23 at 09:17
  • 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 Aug 26 '23 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.

Jens
  • 6,219
  • 2
  • 30
  • 43
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?

TomazicM
  • 25,601
  • 22
  • 29
  • 39