line annotations

This commit is contained in:
Motiejus Jakštys 2019-11-29 16:28:14 +02:00
parent 069c1c1e59
commit 829b93317c
2 changed files with 40 additions and 21 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from math import atan, pi
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
@ -9,14 +10,19 @@ from descartes import PolygonPatch
from measure import * from measure import *
juosta = namedtuple('juosta', ['plotis', 'kryptis', 'dashes', 'spalva']) juosta = namedtuple('juosta', ['plotis', 'kryptis', 'dashes', 'spalva'])
kelias = namedtuple('kelias', ['virsunes', 'plotis', 'kat', 'dashes', 'spalva', 'juostos']) kelias = namedtuple('kelias', ['id', 'virsunes', 'plotis', 'kat', 'dashes', 'spalva', 'juostos'])
# nubraižytos kelio linijos ir jų nubrėžti offset'ai iš dešinės į kairę.
kelias_l = namedtuple('kelias_l', ['id', 'line', 'offsets'])
CONTINUOUS = (1,0) CONTINUOUS = (1,0)
DASHDOTX2 = (10,3,2,3) DASHDOTX2 = (10,3,2,3)
DASHED = (100,20) DASHED = (100,20)
a08 = kelias( keliai = [
kelias(
id='A-08',
virsunes=[1,2,3], virsunes=[1,2,3],
plotis=A08_plotis, plotis=A08_plotis,
kat=KAT1, kat=KAT1,
@ -30,9 +36,9 @@ a08 = kelias(
juosta(L7+L8, 'left', DASHED, 'lightgreen'), juosta(L7+L8, 'left', DASHED, 'lightgreen'),
juosta(L7+L8+L9, 'left', DASHED, 'lightgreen'), juosta(L7+L8+L9, 'left', DASHED, 'lightgreen'),
), ),
) ),
kelias(
a05 = kelias( id='A-05',
virsunes=[4,5,6,7,8,9,10], virsunes=[4,5,6,7,8,9,10],
plotis=A05_plotis, plotis=A05_plotis,
kat=KAT2, kat=KAT2,
@ -42,9 +48,9 @@ a05 = kelias(
juosta(L3, 'right', CONTINUOUS, 'brown'), juosta(L3, 'right', CONTINUOUS, 'brown'),
juosta(L2, 'left', CONTINUOUS, 'brown'), juosta(L2, 'left', CONTINUOUS, 'brown'),
), ),
) ),
kelias(
a03 = kelias( id='A-03',
virsunes=[11,12,13,14,15,16,17,18], virsunes=[11,12,13,14,15,16,17,18],
plotis=A03_plotis, plotis=A03_plotis,
kat=KAT3, kat=KAT3,
@ -52,10 +58,11 @@ a03 = kelias(
spalva='pink', spalva='pink',
juostos=( juostos=(
juosta(L1, 'right', DASHED, 'pink'), juosta(L1, 'right', DASHED, 'pink'),
juosta(0, 'left', DASHED, 'white'),
), ),
) ),
kelias(
g11 = kelias( id='G-11',
virsunes=[19,20,21,22,23], virsunes=[19,20,21,22,23],
plotis=G11_plotis, plotis=G11_plotis,
kat=KAT4, kat=KAT4,
@ -67,28 +74,32 @@ g11 = kelias(
juosta(L12, 'left', CONTINUOUS, 'lightblue'), juosta(L12, 'left', CONTINUOUS, 'lightblue'),
juosta(L12+L13, 'left', CONTINUOUS, 'blue'), juosta(L12+L13, 'left', CONTINUOUS, 'blue'),
), ),
) ),
]
N, E, S, W = (0,15), (15,0), (0,-15), (-15,0) N, E, S, W = (0,10), (10,0), (0,-10), (-10,0)
point_annotations = { point_annotations = {
1: S, 2: E, 3: N, 4: E, 1: S, 2: E, 3: N, 4: W,
5: N, 6: S, 7: S, 8: N, 5: N, 6: S, 7: S, 8: N,
9: E, 10: N, 11: N, 12: N, 9: E, 10: N, 11: S, 12: N,
13: S, 14: W, 15: N, 16: N, 13: S, 14: W, 15: N, 16: N,
17: N, 18: E, 19: N, 20: S, 17: N, 18: E, 19: N, 20: S,
21: N, 22: N, 23: E, 24: N, 21: N, 22: S, 23: E, 24: N,
} }
road_annotations = { 'A-08': W, 'A-05': N, 'A-03': N, 'G-11': E }
# implementacija # implementacija
fig, ax = plt.subplots() fig, ax = plt.subplots()
plt.grid(True) plt.grid(True)
# taškų anotacijos # taškų anotacijos
for v in vertices: for v in vertices:
ax.annotate(v.point, xy=v.xy, zorder=99, textcoords='offset points', xytext=point_annotations[v.point]) ax.annotate(v.point, xy=v.xy, zorder=KAT0, textcoords='offset points', xytext=point_annotations[v.point])
keliai_l = {}
# kelių piešimas # kelių piešimas
for kelias in [a08, a05, a03, g11]: for kelias in keliai:
# ašis # ašis
kelias_line = LineString([Points[i].xy for i in kelias.virsunes]) kelias_line = LineString([Points[i].xy for i in kelias.virsunes])
ax.plot(*kelias_line.xy, linewidth=2, dashes=kelias.dashes, color=kelias.spalva, zorder=kelias.kat) ax.plot(*kelias_line.xy, linewidth=2, dashes=kelias.dashes, color=kelias.spalva, zorder=kelias.kat)
@ -102,6 +113,14 @@ for kelias in [a08, a05, a03, g11]:
# kelio poligonas su plotu # kelio poligonas su plotu
kelias_poly = np.vstack((offset_lines[0].coords, offset_lines[-1].coords)) kelias_poly = np.vstack((offset_lines[0].coords, offset_lines[-1].coords))
ax.add_patch(PolygonPatch(asPolygon(kelias_poly), fc='white', zorder=kelias.kat, linewidth=0)) ax.add_patch(PolygonPatch(asPolygon(kelias_poly), fc='white', zorder=kelias.kat, linewidth=0))
keliai_l[kelias.id] = kelias_l(id=kelias.id, line=kelias_line, offsets=offset_lines)
# kelių anotacijos
for id, kelias in keliai_l.items():
linestart, lineend = np.array(kelias.offsets[-1].coords)[0:2]
delta = lineend - linestart
angle = atan(delta[1]/delta[0])*180/pi
offset = road_annotations[id]
ax.annotate(id, kelias.offsets[-1].coords[0], zorder=KAT0, textcoords='offset points', xytext=offset, rotation=angle)
plt.show() plt.show()

View File

@ -40,7 +40,7 @@ class Vertex:
return (self.coords.lksx, self.coords.lksy) return (self.coords.lksx, self.coords.lksy)
# Kategorijos # Kategorijos
KAT1, KAT2, KAT3, KAT4 = range(4,0,-1) KAT0, KAT1, KAT2, KAT3, KAT4 = range(5,0,-1)
A = Dec('6.094') A = Dec('6.094')
B = Dec('-2.923') B = Dec('-2.923')