~meshing/meshing/urop

« back to all changes in this revision

Viewing changes to shape/overlap-plot.py

  • Committer: Adam Candy
  • Date: 2012-07-06 15:30:52 UTC
  • Revision ID: adam.candy@imperial.ac.uk-20120706153052-63q7bbtir43ts2vp
Import of Varun's branch lp:~varun-verma11/+junk/gshhstoshp into the folder 'shape'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Take collection of circles, see which overlap then plot the shapes with the amended overlaps.
 
2
 
 
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
 
7
 
 
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] ) ]
 
12
 
 
13
# See which circles overlap and store in list.
 
14
# a.intersects(b)
 
15
overlapping = []
 
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]) 
 
21
 
 
22
# Create a new shape from the overlain circles.
 
23
join = cascaded_union(overlapping)
 
24
 
 
25
# Take the coords. of the perimeter of this new shape.
 
26
coords = list(join.exterior.coords)
 
27
 
 
28
# Store x-y coords of the perimeter in two lists to plot.
 
29
x = []; y = []
 
30
for i in range(len(coords)):
 
31
        x.append(coords[i][0]); y.append(coords[i][1])
 
32
 
 
33
# Plot results.
 
34
print coords
 
35
pyplot.plot(x, y)
 
36
#pyplot.xlim(-4, 4)
 
37
#pyplot.ylim(-4, 4)
 
38
pyplot.show()