This is a follow up to Intersecting MultiLinestring based geodataframes with geopandas? in which I was trying to intersect polyline layers and carry the attributes over to a resulting overlay/intersected layer. I did receive a response to this previous question but unfortunately was not able to extend the code provided to this more realistic and complex 2 dimensional case. Ultimately I would like to perform this for large shapefiles with thousands of segments carrying many attributes.
My new limited working example is as follows:
In the above figure red nodes are vertices, black lines are line segments, blue letters/numbers are attributes for each segment, and black numbers are the lengths of each line segment. Notice that the bottom figure is an intersection of both geometry and attribute data. Here are the wkt
strings for the top left figure:
MULTILINESTRING ((0 0, 6.656423206909781 4.437570291332059))
MULTILINESTRING ((6.656423206909781 4.437570291332059, 8.070636769282876 5.851783853705154))
MULTILINESTRING ((8.070636769282876 5.851783853705154, 14.33789797945475 13.64417995012345))
MULTILINESTRING ((6.656423206909781 4.437570291332059, 10.98655022583197 1.937570291332059))
MULTILINESTRING ((10.98655022583197 1.937570291332059, 13.68293236472948 0.6224568509648269))
MULTILINESTRING ((13.68293236472948 0.6224568509648269, 17.54663566988575 -0.412819329445256))
MULTILINESTRING ((17.54663566988575 -0.412819329445256, 18.41266107367019 -0.912819329445255))
Here are the wkt
strings for the top right figure
LINESTRING (0 0, 4.160264504318614 2.773481432082537)
LINESTRING (4.160264504318614 2.773481432082537, 6.656423206909781 4.437570291332059)
LINESTRING (6.656423206909781 4.437570291332059, 8.070636769282876 5.851783853705154, 9.950815132334437 8.189502682630641)
LINESTRING (9.950815132334437 8.189502682630641, 13.08444573742037 12.08570073083979)
LINESTRING (13.08444573742037 12.08570073083979, 14.33789797945475 13.64417995012345)
LINESTRING (6.656423206909781 4.437570291332059, 10.98655022583197 1.937570291332059, 10.98655022583197 1.937570291332057)
LINESTRING (10.98655022583197 1.937570291332057, 13.68293236472948 0.6224568509648269, 15.61478401730761 0.104818760759786)
LINESTRING (15.61478401730761 0.104818760759786, 17.54663566988575 -0.412819329445256, 18.41266107367019 -0.912819329445255)
Running this through the script provided by @Jon in their answer to Intersecting MultiLinestring based geodataframes with geopandas? gives the following result (only geometry is shown)
LINESTRING (0 0, 4.160264504318614 0)
LINESTRING (4.160264504318614 0, 6.656423206909781 0)
LINESTRING (6.656423206909781 0, 8.070636769282876 0)
LINESTRING (8.070636769282876 0, 9.950815132334437 0)
LINESTRING (9.950815132334437 0, 10.98655022583197 0)
LINESTRING (10.98655022583197 0, 10.98655022583197 0)
LINESTRING (10.98655022583197 0, 13.08444573742037 0)
LINESTRING (13.08444573742037 0, 13.68293236472948 0)
LINESTRING (13.68293236472948 0, 14.33789797945475 0)
LINESTRING (14.33789797945475 0, 15.61478401730761 0)
LINESTRING (15.61478401730761 0, 17.54663566988575 0)
LINESTRING (17.54663566988575 0, 18.41266107367019 0)
Which is a straight line, and thus incorrect.
How can I accomplish this operation using python
and preferably shapely
or geopandas
? If shapely
and geopandas
are not suitable tools, which are the suitable tools for this?
It is very important for me to carry the attributes over as well.
No comments:
Post a Comment