1
# Take collection of circles, see which overlap then plot the shapes with the amended overlaps.
3
from shapely.geometry import Polygon, Point
4
from shapely.ops import cascaded_union
5
from matplotlib import pyplot
6
from shapely.validation import explain_validity
8
# definses one polygon square.
9
plist = [[(0, 0), (0, 2), (2, 2),(2,0), (0,0)],[(0,1),(5,1),(5,1.5),(0,1.5),(0,1)]]
10
# Take the points given and creates polygons.
11
polygons = [Polygon(plist[0]),Polygon(plist[1] ) ]
13
# See which circles overlap and store in list.
16
for n in range(len(polygons) - 1):
17
if polygons[n].intersects(polygons[n+1]) == True:
18
# Two if statements to make sure the same polygon isn't being entered more than once.
19
if polygons[n] not in overlapping: overlapping.append(polygons[n])
20
if polygons[n + 1] not in overlapping: overlapping.append(polygons[n + 1])
22
# Create a new shape from the overlain circles.
23
join = cascaded_union(overlapping)
25
# Take the coords. of the perimeter of this new shape.
26
coords = list(join.exterior.coords)
28
# Store x-y coords of the perimeter in two lists to plot.
30
for i in range(len(coords)):
31
x.append(coords[i][0]); y.append(coords[i][1])