-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinearring.py
More file actions
59 lines (43 loc) · 1.24 KB
/
Copy pathlinearring.py
File metadata and controls
59 lines (43 loc) · 1.24 KB
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
from matplotlib import pyplot
from shapely.geometry.polygon import LinearRing
from figures import SIZE
COLOR = {
True: '#6699cc',
False: '#ff3333'
}
def v_color(ob):
return COLOR[ob.is_valid]
def plot_coords(ax, ob):
x, y = ob.xy
ax.plot(x, y, 'o', color='#999999', zorder=1)
def plot_line(ax, ob):
x, y = ob.xy
ax.plot(x, y, color=v_color(ob), alpha=0.7, linewidth=3, solid_capstyle='round', zorder=2)
fig = pyplot.figure(1, figsize=SIZE, dpi=90)
# 1: valid ring
ax = fig.add_subplot(121)
ring = LinearRing([(0, 0), (0, 2), (1, 1), (2, 2), (2, 0), (1, 0.8), (0, 0)])
plot_coords(ax, ring)
plot_line(ax, ring)
ax.set_title('a) valid')
xrange = [-1, 3]
yrange = [-1, 3]
ax.set_xlim(*xrange)
ax.set_xticks(range(*xrange) + [xrange[-1]])
ax.set_ylim(*yrange)
ax.set_yticks(range(*yrange) + [yrange[-1]])
ax.set_aspect(1)
#2: invalid self-touching ring
ax = fig.add_subplot(122)
ring2 = LinearRing([(0, 0), (0, 2), (1, 1), (2, 2), (2, 0), (1, 1), (0, 0)])
plot_coords(ax, ring2)
plot_line(ax, ring2)
ax.set_title('b) invalid')
xrange = [-1, 3]
yrange = [-1, 3]
ax.set_xlim(*xrange)
ax.set_xticks(range(*xrange) + [xrange[-1]])
ax.set_ylim(*yrange)
ax.set_yticks(range(*yrange) + [yrange[-1]])
ax.set_aspect(1)
pyplot.show()