The native shapely function is unary_union
(Planar graph)
The circles
1) Using the script of How to find the intersection areas of overlapping buffer zones in single shapefile?
rings = [LineString(pol.exterior.coords) for pol in circles]
union = unary_union(rings)
result = [geom for geom in polygonize(union)]
Result: you have all the intersections
2) You can also use other solutions according to the position of an element in a list (look at Shapely/ Python looping through a number of polygons
with itertools)
import itertools
for i,j in itertools.combinations(enumerate(circles), 2):
if i[1].intersects(j[1]):
print "polygons", i[0],j[0]
polygons 0 1
polygons 1 2
for i,j in itertools.permutations(enumerate(circles), 2):
if i[1].intersects(j[1]):
print "polygons", i[0],j[0]
polygons 0 1
polygons 1 0
polygons 1 2
polygons 2 1
3) you can use a spatial index as rtree (look at Faster way of polygon intersection with shapely)
from rtree import index
idx = index.Index()
# create the spatial index
for pos, cell in enumerate(circles):
idx.insert(pos, cell.bounds)
# loop through each polygon
for poly in circles:
# Merge cells that have overlapping bounding boxes
merged_cells = unary_union([circles[pos] for pos in idx.intersection(poly.bounds)])
# Do actual intersection
poly.intersection(merged_cells)
(the two intersections here)
circles
?! I edit the question.unary_union
look at How to find the intersection areas of overlapping buffer zones in single shapefile?