5

I want to create a center line for a river (polygon). I thought about simply creating a new line manually, but it would be a long and imperfect process. If there is a way to automate this process, that would be much better.

Can anyone help?

0

2 Answers 2

4

You can do so by following the procedures expressed in this answer. Here's how to implement it in QGIS:

  1. Make sure your lines are dense enough: This method requires a high number of vertices in your polylines. The higher, the better the resulting centreline will be (but too high also has a drawback, see step 5). You may test the method below with your existing geometries, and if the result isn't satisfying, come back here and further densify it. To do so, go to Processing Toolbox -> Densify Geometries Given an Interval.

Densified Polylines

  1. Get the vertices from your lines: To do that, go to Vector -> Geometries -> Extract nodes.

Vertices from Polylines

  1. Make Voronoi polygon: This is the crux of it. Voronoi polygons are not meant for this, but the boundaries between the polygons inadvertely trace a path between the sets of points (the sets being each river margin, in this case). The denser the points, the straighter the boundary will appear to be.

Voronoi polygon

  1. Select lines that touch the river margins: To do this, first need to convert it to polylines. Go to Vector -> Geometries -> Polygon to Lines. Then, go to Processing Toolbar -> Explode Lines. Finally, go to Vector -> Investigate -> Select By Location, and select any linestring that touches your original river margins layer.

Voronoi selected

  1. Delete these lines: There are likely still a few lines to be cleaned up, depending on how dense your Voronoi triangulation was. If all you have left are lines outside your river, and the centreline, then you can delete the outside lines by creating polygons using the river margins and the bounding box, and selecting any lines that are contained in them. If there are left-over lines inside, perpendicular to the centreline, you might want to redo the process with a less dense network.

Leftover Voronoi

  1. Merge the centreline and smooth it: Once you cleaned up the unwanted linestrings and is left only with the ones that form your centreline, select them all and merge them (Edit -> Merge selected features). Finally, you go to Processing Toolbox -> Smooth geometry, and do as many passes until you're satisfied with it visually.

Final Centreline

This method is a bit rough on the edges, depending on how big your features are it may be faster to vectorize it by hand, but it gets the job done. It also has room for improvement, especially on step 5.

1
  • Thanks for documenting this method. A question: it seems the overall length of the new centerline linestring is much longer than the actual distance from one end to the other. I am still debugging / trying to figure this out, but is it possible there are two perfectly overlapping sets of linestrings? Jan 10, 2020 at 15:07
1

I would try converting your river polygon to lines to extract each bank, then using the QChainage plugin. It will allow you to create a set of points at fixed distances along both of your river bank lines. Then average the x and y coordinates of those points to get center points for the river. After that, simply use the Points2One plugin or something similar to create a line from the average points that you calculated in the previous step.

2
  • Thanks a lot! Can you clarify how you would "average the x and y coordinates"?
    – Rashomon
    Jan 25, 2018 at 15:44
  • You bet. There are a bunch of ways you can do it, but here's one potential method @Rashomon. For the set of points along each river bank, add new fields to the attribute table for Xcoord and Ycoord. Then open field calculator and use the $x and $y functions to populate the fields. You can then use anything you want to compute a simple average of the two sets of coordinates. Even Excel will work. Then just plot your new x and y coordinates that correspond to the center of the river.
    – lambertj
    Jan 25, 2018 at 16:44

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