-
Notifications
You must be signed in to change notification settings - Fork 11
/
MapExtractor.py
55 lines (45 loc) · 1.41 KB
/
MapExtractor.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
from matplotlib import colors
import matplotlib.pyplot as plt
import sys
import numpy as np
def get_map_data_blocks(file):
flag = ''
next = -1
blocks = []
with open(file, 'r') as map:
for line in map:
line = line[:-1]
if line == '-':
next += 1
blocks.append([[],[],[],[]])
else:
rxylxy = [float(e.replace(",", ".")) for e in line.split(" ")]
for i in range(4):
blocks[next][i].append(rxylxy[i])
return blocks
def get_map_data(file):
blocks = [[0, 0, 0, 0]]
with open(file, 'r') as map:
for line in map:
line = line[:-1]
if line == '-':
blocks.pop()
else:
rxylxy = [float(e.replace(",", ".")) for e in line.split(" ")]
blocks.append(rxylxy[0:4])
return np.array(blocks)
def plot_map(blocks):
plt.plot(blocks.T[0], blocks.T[1], color = 'tab:blue')
plt.plot(blocks.T[2], blocks.T[3], color = 'tab:orange')
plt.gca().invert_xaxis()
plt.axis("equal")
def plot_map_blocks(blocks):
for block in blocks:
plt.plot(block[0], block[1], color = 'tab:blue')
plt.plot(block[2], block[3], color = 'tab:orange')
plt.gca().invert_xaxis()
plt.axis("equal")
if __name__ == '__main__':
blocks = get_map_data(sys.argv[1])
plot_map(blocks)
plt.show()