-
Notifications
You must be signed in to change notification settings - Fork 2
/
shapely_test_case.py
151 lines (130 loc) · 3.15 KB
/
shapely_test_case.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Shapely_test_case
"""
a test case to determine whether or not shapely polygon patch calculates the
area that I expect when there is overlap.
Test cases are of interest
case 1 - independant coords
two unit coords with a half unit stack spaced 1.5 units apart
case 2 - touching polygons
two coords with half unit stack space 1 unit appart
case 3 overlap
two coords with half unit stack spaced half unit appart
case 4 - crossing coords
two perpendicular coords with half init stack
"""
import matplotlib.pyplot as plt
from shapely.geometry import MultiLineString
from descartes.patch import PolygonPatch
def case1():
"""
expected
length
2.0
area
1 + 1 + 2 * 0.7854 = 3.5708
Returns
-------
"""
line1 = [(0, 0), (1, 0)]
line2 = [(0, 1.5), (1, 1.5)]
lines = [line1,line2]
line = MultiLineString(lines)
dilated = line.buffer(0.5)
length = line.length
area = dilated.area
print("length : {0} \t area {1}:".format(length, area))
return lines
def case2():
"""
expected
length
2.0
area
1 + 1 + 2 * 0.7854 = 3.5708
Returns
-------
"""
line1 = [(0, 0), (1, 0)]
line2 = [(0, 1.0), (1, 1.0)]
lines = [line1,line2]
line = MultiLineString(lines)
dilated = line.buffer(0.5)
length = line.length
area = dilated.area
print("length : {0} \t area {1}:".format(length, area))
return lines
def case3():
"""
expected
length
2.0
area
2.762
Returns
-------
"""
line1 = [(0, 0), (1, 0)]
line2 = [(0, 0.5), (1, 0.5)]
lines = [line1,line2]
line = MultiLineString(lines)
dilated = line.buffer(0.5)
length = line.length
area = dilated.area
print("length : {0} \t area {1}:".format(length, area))
return lines
def case4():
"""
expected
length
2.0
area
1 + 2 * o.76 = 2.5682742
Returns
-------
"""
line1 = [(-0.5, 0), (0.5, 0)]
line2 = [(0, -0.5), (0, 0.5)]
lines = [line1,line2]
line = MultiLineString(lines)
dilated = line.buffer(0.5)
length = line.length
area = dilated.area
print("length : {0} \t area {1}:".format(length, area))
return lines
def case5():
"""
expected
length
2.0
area
1 + 0.76 = 1.76
Returns
-------
"""
line1 = [(0, 0), (0, 1)]
line2 = [(0, 0), (0, 1)]
lines = [line1,line2]
line = MultiLineString(lines)
dilated = line.buffer(0.5)
length = line.length
area = dilated.area
print("length : {0} \t area {1}:".format(length, area))
return lines
def plot(lines):
fig = plt.figure(1, figsize=(5, 5), dpi=180)
ax = fig.add_subplot(111)
line = MultiLineString(lines)
dilated = line.buffer(0.5)
patch1 = PolygonPatch(dilated, facecolor='#99ccff', edgecolor='#6699cc')
ax.add_patch(patch1)
for i in range(len(lines)):
x, y = line[i].xy
plt.axis('equal')
ax.plot(x, y, color='#999999')
plt.show()
case1()
case2()
case3()
case4()
case5()
plot(case5())