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
use std::collections::BTreeMap;
use serde::Serialize;
use abstutil::Timer;
use map_model::{osm, Direction, DrivingSide, LaneType, Map, Road};
pub fn run(map_path: String) {
let map = Map::load_synchronously(map_path, &mut Timer::throwaway());
let driving_side = match map.get_config().driving_side {
DrivingSide::Right => "right",
DrivingSide::Left => "left",
};
let mut tests = Vec::new();
for road in map.all_roads() {
if let Some(tc) = transform(road, driving_side) {
tests.push(tc);
}
}
println!("{}", abstutil::to_json(&tests));
}
#[derive(Serialize)]
struct TestCase {
way: String,
tags: BTreeMap<String, String>,
driving_side: String,
output: Vec<LaneSpec>,
}
#[derive(Serialize)]
struct LaneSpec {
#[serde(rename = "type")]
lane_type: String,
direction: String,
}
fn transform(road: &Road, driving_side: &str) -> Option<TestCase> {
let mut result = TestCase {
way: road.orig_id.osm_way_id.to_string(),
tags: strip_tags(road.osm_tags.clone().into_inner()),
driving_side: driving_side.to_string(),
output: Vec::new(),
};
for lane in &road.lanes {
result.output.push(LaneSpec {
lane_type: match lane.lane_type {
LaneType::Driving => "driveway",
LaneType::Parking => "parking_lane",
LaneType::Sidewalk => "sidewalk",
LaneType::Shoulder => "shoulder",
LaneType::Biking => "cycleway",
LaneType::Bus => {
return None;
}
LaneType::SharedLeftTurn => "shared_left_turn",
LaneType::Construction => {
return None;
}
LaneType::LightRail => {
return None;
}
LaneType::Buffer(_) => {
return None;
}
}
.to_string(),
direction: match lane.dir {
Direction::Fwd => "forward",
Direction::Back => "backward",
}
.to_string(),
});
}
Some(result)
}
fn strip_tags(mut tags: BTreeMap<String, String>) -> BTreeMap<String, String> {
tags.remove(osm::OSM_WAY_ID);
tags.remove(osm::ENDPT_FWD);
tags.remove(osm::ENDPT_BACK);
tags.remove(osm::INFERRED_PARKING);
tags.remove(osm::INFERRED_SIDEWALKS);
tags.remove("maxspeed");
tags.remove("name");
tags.remove("old_ref");
tags.remove("ref");
tags
}