Skip to main content
2 of 5
Improved English
Hornbydd
  • 44.6k
  • 5
  • 42
  • 84

How to split up Linestrings based on type and connectivity?

I am working with a road network, where I extracted only the three main road types. In the next step, I would like to union all Linestrings based on their road type and connectivity. That means that I have a gdf of thousands of Linestrings right now but want to end up with only six Linestrings (see image below).

So, red, green and blue are the three road types and therefore cannot be unioned together. On top of that 3, 4, 5, and 6 are the same type but are not connected to each other but with another class.

I looked into dissolved but the problem here is that it ignores connectivity. On the other side, unary_union looks suitable but only returns shapely geometries which I would have to transform back into a gdf (as far as I'm concerned?). Any idea how to approach this problem?

Road Network

Danny
  • 35
  • 5