-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_vis_without_lanelet.py
171 lines (140 loc) · 5.48 KB
/
map_vis_without_lanelet.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import matplotlib
import matplotlib.axes
import matplotlib.pyplot as plt
import xml.etree.ElementTree as xml
import pyproj
import math
import os
import pandas as pd
import dict_utils
import files
xs = []
ys = []
mode = 0
"""
def getpoints():
global mode
mode = 1
mappoints = pd.read_csv("Generated Files/Map Coordinates.csv")
print("Dataframe of Map Coordinates that makes Curbstone border")
print(mappoints)
#mappoints = np.loadtxt("mappoints.csv", delimiter=",", dtype=float)
#os.remove("mappoints.csv")
return mappoints
"""
class Point:
def __init__(self):
self.x = None
self.y = None
class LL2XYProjector:
def __init__(self, lat_origin, lon_origin):
self.lat_origin = lat_origin
self.lon_origin = lon_origin
self.zone = math.floor((lon_origin + 180.) / 6) + 1 # works for most tiles, and for all in the dataset
self.p = pyproj.Proj(proj='utm', ellps='WGS84', zone=self.zone, datum='WGS84')
[self.x_origin, self.y_origin] = self.p(lon_origin, lat_origin)
def latlon2xy(self, lat, lon):
[x, y] = self.p(lon, lat)
return [x - self.x_origin, y - self.y_origin]
def get_type(element):
for tag in element.findall("tag"):
if tag.get("k") == "type":
return tag.get("v")
return None
def get_subtype(element):
for tag in element.findall("tag"):
if tag.get("k") == "subtype":
return tag.get("v")
return None
def get_x_y_lists(element, point_dict):
x_list = list()
y_list = list()
for nd in element.findall("nd"):
pt_id = int(nd.get("ref"))
point = point_dict[pt_id]
x_list.append(point.x)
y_list.append(point.y)
return x_list, y_list
def set_visible_area(point_dict, axes):
min_x = 10e9
min_y = 10e9
max_x = -10e9
max_y = -10e9
for id, point in dict_utils.get_item_iterator(point_dict):
min_x = min(point.x, min_x)
min_y = min(point.y, min_y)
max_x = max(point.x, max_x)
max_y = max(point.y, max_y)
axes.set_aspect('equal', adjustable='box')
axes.set_xlim([min_x - 10, max_x + 10])
axes.set_ylim([min_y - 10, max_y + 10])
def draw_map_without_lanelet(filename, axes, lat_origin, lon_origin):
assert isinstance(axes, matplotlib.axes.Axes)
global xs
global ys
axes.set_aspect('equal', adjustable='box')
axes.patch.set_facecolor('lightgrey')
projector = LL2XYProjector(lat_origin, lon_origin)
e = xml.parse(filename).getroot()
point_dict = dict()
for node in e.findall("node"):
point = Point()
point.x, point.y = projector.latlon2xy(float(node.get('lat')), float(node.get('lon')))
point_dict[int(node.get('id'))] = point
set_visible_area(point_dict, axes)
unknown_linestring_types = list()
for way in e.findall('way'):
way_type = get_type(way)
if way_type is None:
raise RuntimeError("Linestring type must be specified")
elif way_type == "curbstone":
type_dict = dict(color="black", linewidth=1.5, zorder=10)
elif way_type == "line_thin":
way_subtype = get_subtype(way)
if way_subtype == "dashed":
type_dict = dict(color="white", linewidth=1, zorder=10, dashes=[10, 10])
else:
type_dict = dict(color="white", linewidth=1, zorder=10)
elif way_type == "line_thick":
way_subtype = get_subtype(way)
if way_subtype == "dashed":
type_dict = dict(color="white", linewidth=2, zorder=10, dashes=[10, 10])
else:
type_dict = dict(color="white", linewidth=2, zorder=10)
elif way_type == "pedestrian_marking":
type_dict = dict(color="green", linewidth=1, zorder=10, dashes=[5, 10])
elif way_type == "bike_marking":
type_dict = dict(color="white", linewidth=1, zorder=10, dashes=[5, 10])
elif way_type == "stop_line":
type_dict = dict(color="white", linewidth=3, zorder=10)
elif way_type == "virtual":
type_dict = dict(color="blue", linewidth=1.2, zorder=10, dashes=[2, 5])
elif way_type == "road_border":
type_dict = dict(color="black", linewidth=1.5, zorder=10)
elif way_type == "guard_rail":
type_dict = dict(color="black", linewidth=1, zorder=10)
elif way_type == "traffic_sign":
continue
else:
if way_type not in unknown_linestring_types:
unknown_linestring_types.append(way_type)
continue
x_list, y_list = get_x_y_lists(way, point_dict)
plt.plot(x_list, y_list, **type_dict)
"""
if way_type == "curbstone":
xs.extend(x_list)
ys.extend(y_list)
#plt.savefig(f"{files.MAP_DATA}/Map.png")
"""
#if len(unknown_linestring_types) != 0:
#print("Found the following unknown types, did not plot them: " + str(unknown_linestring_types))
"""
if mode == 0:
if False == os.path.exists("Generated Files/Map Coordinates.csv"):
tempdict = {'x': xs, 'y': ys}
df = pd.DataFrame(tempdict)
df = df.drop_duplicates()
dfx = df.sort_values(by=['x', 'y'])
#dfx.to_csv(f"{files.MAP_DATA}/Map Coordinates.csv", index = False)
"""