I have one data list as follows:
from shapely.geometry import box data = [box(1,2,3,4), box(5,6,7,8), box(1,2,3,4)] codes = ['A','B','C']
The data list has the following elements :
A = box(1,2,3,4) B = box(5,6,7,8) C = box(1,2,3,4)
I need to check if an element intersects with any other elements. If they intersect, they must fit in one tuple; and if they do not intersect, they must be placed in different tuples. Expected Result:
result = [(A,C), (B)]
How to do it?
I tried this as:
results = [] for p,c in zip(data,codes): for x in data: if p.intersects(x): ##.intersects return true if they overlap else false results.append(c) print results
hiker source share