Tuesday, 3 July 2018

qgis - Simplifying multiple lines to create central axis?



I have a layer with railway lines, downloaded from OpenStreetMap. Every single track is represented separately, so at trainstations, you have several parallel lines, as well as sidelines that lead to depots. Sometimes, lines are broken (it's OSM!). I want to reduce all these lines to one single, simple line.


An idea is to create buffers around the railway lines and to dissolve them to a single polygon (and maybe apply a negative buffer to reduce its width and generalize the geometry)?


Railway lines, Buffer and vertices of the buffer


If I could create a medial axis from this polygon,, it would represent quite well the simplified railway line I want to create.


However, how to create such a medial axis in QGIS?


There is a solution in PostGIS: https://postgis.net/docs/ST_ApproximateMedialAxis.html


But unfortunately, I have no experience with postgis, so I'm looking for a solution inside QGIS. A possible solution seems to be the HCMGIS-plugin that has a function "Create Skeleton/Medial Axis". The result represents quite well the railway-track (see screenshot, red line), but with one major problem: it creates a skeleton with small side-lines connecting to the vertices of the simplified buffer.


Original railway line, simplified buffer and skeleton in red


Second problem: algorith takes quite long for a larger selection - I was able to test it only with a small selection as the calculation for the whole railway-network did not stop even after half an hour. I'm not sure if it works well for the whole network (see screenshot 3 with the red part representing the selection used for testing). enter image description here


Any idea for alternative solutions?





@Cyril's suggestion of using the midline of the skeltonize method would be perfect for me, but unfortunately, the resulting layer consists of only one object - so the short lines are not separated from the long one.


Maybe there is also a completely different method for solving my problem?


Update: see PostGIS-syntax: export query-result to QGIS / Shapefile




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...