I would like to perform the following operation using geopandas
.
The segments are delimited by red points and the blue items are attribute information. My inputs are the first and second line segments and my output is the third line segment.
Initially I thought this would be an intersection operation, but I soon learned that geopandas
can only intersect polygons, therefore something like:
intersection = geopandas.overlay(split_lines, original_lines, how='intersection')
returns the following error:
raise TypeError("overlay only takes GeoDataFrames with (multi)polygon "
TypeError: overlay only takes GeoDataFrames with (multi)polygon
This to me looks like a standard geoprocessing operation and I really hope I won't have to code this up from scratch. Are there any simplified ways to come up with the following result without having to code a custom function?
EDIT
Unfortunately I cannot get this to work for more complicated geometries such as
ORIGINAL_LINES
geometry property
0 (LINESTRING (0 0, 6.656423206909781 4.43757029... a
1 (LINESTRING (6.656423206909781 4.4375702913320... b
2 (LINESTRING (8.070636769282876 5.8517838537051... c
3 (LINESTRING (6.656423206909781 4.4375702913320... d
4 (LINESTRING (10.98655022583197 1.9375702913320... e
5 (LINESTRING (13.68293236472948 0.6224568509648... a
6 (LINESTRING (17.54663566988575 -0.412819329445... a
SPLIT_LINES
geometry susc
0 LINESTRING (0 0, 4.160264504318614 2.773481432... 1
1 LINESTRING (4.160264504318614 2.77348143208253... 2
2 LINESTRING (6.656423206909781 4.43757029133205... 3
3 LINESTRING (9.950815132334437 8.18950268263064... 4
4 LINESTRING (13.08444573742037 12.0857007308397... 5
5 LINESTRING (6.656423206909781 4.43757029133205... 4
6 LINESTRING (10.98655022583197 1.93757029133205... 3
7 LINESTRING (15.61478401730761 0.10481876075978... 2
The output seem to be a 1D line… which is incorrect for this application.
Best Answer
EDIT: The following answer only works for the 1-D case. To extend it to 2-D, you will need to parameterize your links by the along-road distance, and replace the x-coordinate with the parameterized length. However, I'm fairly confident this is doable much simpler with Geopandas.
It would be too hard to give hints in the comments, so here's a script that should give you what you want. It's not written for efficiency--probably you could get geopandas to do what you want with some finegaling, but here ya go. It's also not written very generally, but that could be done if you have more than one attribute.
Result: