I have two line paths (non straight lines) and I would like to determine at which segment they intersect. My first line consists of 97 points and the other line consists of 50 points and they intersect at one point. I will use a smaller data set below for simplicity. I am able to find the intersections point using Shapely intersection
method but I'm having a hard time finding the segment.
from shapely.geometry import *
a = [[1246.27886576, 397.92212558], [1257.07143932, 386.62625213], [1248.9911559 , 364.85303935], [1243.15355998, 351.2073384 ], [1252.96611444, 345.8853271 ], [1259.99528981, 343.00414527]]
b = [ [1234.5260801 , 364.17967993], [1243.18178589, 363.32934182], [1251.03950905, 360.78543246], [1256.76030287, 358.07463708], [1293.17663569, 365.07308725], [1311.17586247, 368.66783979]]
line1 = LineString(a)
line2 = LineString(b)
point = line1.intersection(line2)
## point is (1247.711909530379 361.8627307297313)
Then I have the following to find the line segment that has the intersection in "a"
for x in range(len(a)-1):
line = LineString(a[x:x+2])
if(point.within(line)):
print(x)
The problem is that I am getting nothing. By looking visually at the point, I expect that the point would be between the third and fourth point. But the "point within" is returning false. I am suspecting the equality is lost due to decimal points.
Is there any way I can find the segment of intersection?