[GIS] Collapsing parallel lines into a single line QGIS

mergeqgisshapefile

I have a shapefile of the Washington metro area, but along much of the route multiple lines run parallel to each other (see picture 1) and I need to collapse them into a single line.

I've tried creating a buffer and dissolving the result, which visually achieves what I'm looking for but ultimately I need a single shapefile line representing the center line that I can then run the qchainage process on but so far haven't been able to achieve that.

Does anyone have a way to achieve this in QGIS?

I believe I'm essentially trying to replicate the 'Collapse Dual Lines To Centerline' functionality in ArcGIS.

Input shapefile:

enter image description here

Dissolve Buffer result:
enter image description here

Best Answer

I have a function that returns a parallel line from three parameters, a line object, a left or right, and a distance. The returned line is parallel to the left or right of the given line a distance of the given distance.

The function takes each node of the given line and computes the center of a tangent circle (90 degrees to left or right of the current bearing) with a radius of the given distance and uses the center of the circle as the node's parallel point.

After the function returns the new line, I reverse order the the nodes of the returned parallel line if its drawn direction does not match the given line.

For street center lines, the original line must accommodate extensions to intersections.