I have two large lists of polygons.
Using python, I want to take each polygon in list 1 and find the results of its geometric intersection with the polygons in list 2 (I use shapely ).
So, for a polygon, I in list 1 may have several polygons in list 2 that will intersect with it.
The problem is that both lists are large, and if I just nest two loops and run the intersection command for each Possible pair of polygons, it takes a very long time. I am not sure if it would be much faster to do this before crossing the boolean test (for example, if crossing: return the intersection).
What would be a good way to sort or organize these two lists of polygons to make intersections more efficient? Is there a sorting algorithm that matches this situation and that I could do with python?
I am relatively new to programming and have no background in discrete mathematics, so if you know the existing algorithm that I should use (which, I believe, exists for such situations), please provide a link or explanation that could help me really actually implementing it in python.
Also, if there is a better StackExchange site for this question, let me know. I feel that these are the bridges of general python, gis and geometry programming, so I was not sure.
source share