Handri
Handri

Reputation: 21

Dissolve Lines in Python

I have a shapefile with multiple lines. I am looking for a method to dissolve all the touching lines. This was possible in ArcMap but can't seem to do it either in Python nor QGIS:

Before: enter image description here

Desired output: enter image description here

This needs to be done on multiple lines, therefore doing it manually like in QGIS merge is not an option.

In ArcMap I used to Dissolve and multipart. Not needing to use any attributes.

Upvotes: 0

Views: 573

Answers (2)

Marlon
Marlon

Reputation: 13

I had a similar problem, which I posted in the question: Spatially dissolve lines that intersect, after attending tabular conditions.

I solved using linemerge() from shapely.ops followed by for looping in geometry.geoms to separate the parts when the result from linemerge was a 'MultiLineString'.

Please share your code for a better answer!

Upvotes: 0

user18423483
user18423483

Reputation:

First you must dissolve all the lines, you can use this tool: 24.1.16.22. Dissolve, then you convert to single part with the 24.1.16.46. Multipart to singleparts tool.

Upvotes: 1

Related Questions