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?
Answer
You can do so by following the procedures expressed in this answer. Here's how to implement it in QGIS:
- 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.
- Get the vertices from your lines: To do that, go to Vector -> Geometries -> Extract nodes.
- 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.
- 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.
- 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.
- 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.
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.
No comments:
Post a Comment