Having around 2000 rows with multiline string coordinates I am implementing code to see where they intersect.
0 MULTILINESTRING ((-2.50909 53.07879, -2.50867 ...
1 MULTILINESTRING ((-2.49312 53.06901, -2.49269 ...
code:
from shapely.geometry import *
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
sample = gpd.read_file('cleaned_links_v2.geojson')
df = sample['geometry']
line_gdf = sample.iloc[0:2000]
ma = line_gdf.geometry.apply(lambda g: line_gdf.intersects(g))
ma
That code gives me a matrix where I have True or False weather 2 lines are intersecting with each other.
0 1 2 3 4 5 6 7 8 9 ... 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999
0 True False False False True False True False False False ... False False False False False False False False False False
1 False True False False False False False False False False ... False False False False False False False False False False
2 False False True True False True False True False False ... False False False False False False False False False False
3 False False True True False False False False False False ... False False False False False False False False False False
4 True False False False True False True False False False ... False False False False False False False False False False
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1995 False False False False False False False False False False ... False False False False True True False False False False
1996 False False False False False False False False False False ... False False False False False False True False False True
1997 False False False False False False False False False False ... False False False False False False False True True False
1998 False False False False False False False False False False ... False False False False False False False True True True
1999 False False False False False False False False False False ... False False False False False False True False True True
I would like table where per Node (intersection) I got list of all edges that are intesecting here. Count of them would also be good.
something in any form of following: Node ID 1 | Edge 1 | Edge 2 | Edge 7 | count = 3
I got now
import shapely
L1 = MultiLineString(df[2])
L2 = MultiLineString(df[2])
print(L1.intersection(L2))
So I can get coordinates of intersection