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
use std::fmt;
use serde::{Deserialize, Serialize};
pub const NAME: &str = "name";
pub const HIGHWAY: &str = "highway";
pub const MAXSPEED: &str = "maxspeed";
pub const PARKING_RIGHT: &str = "parking:lane:right";
pub const PARKING_LEFT: &str = "parking:lane:left";
pub const PARKING_BOTH: &str = "parking:lane:both";
pub const SIDEWALK: &str = "sidewalk";
pub const OSM_WAY_ID: &str = "abst:osm_way_id";
pub const OSM_REL_ID: &str = "abst:osm_rel_id";
pub const ENDPT_FWD: &str = "abst:endpt_fwd";
pub const ENDPT_BACK: &str = "abst:endpt_back";
pub const INFERRED_PARKING: &str = "abst:parking_inferred";
pub const INFERRED_SIDEWALKS: &str = "abst:sidewalks_inferred";
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
pub enum RoadRank {
Local,
Arterial,
Highway,
}
impl RoadRank {
pub fn from_highway(hwy: &str) -> RoadRank {
match hwy {
"motorway" | "motorway_link" => RoadRank::Highway,
"trunk" | "trunk_link" => RoadRank::Highway,
"primary" | "primary_link" => RoadRank::Arterial,
"secondary" | "secondary_link" => RoadRank::Arterial,
"tertiary" | "tertiary_link" => RoadRank::Arterial,
_ => RoadRank::Local,
}
}
pub fn detailed_from_highway(hwy: &str) -> usize {
for (idx, x) in vec![
"motorway",
"motorway_link",
"trunk",
"trunk_link",
"primary",
"primary_link",
"secondary",
"secondary_link",
"tertiary",
"tertiary_link",
"unclassified",
"residential",
"cycleway",
]
.into_iter()
.enumerate()
{
if hwy == x {
return 100 - idx;
}
}
0
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct NodeID(pub i64);
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct WayID(pub i64);
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct RelationID(pub i64);
impl fmt::Display for NodeID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "https://www.openstreetmap.org/node/{}", self.0)
}
}
impl fmt::Display for WayID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "https://www.openstreetmap.org/way/{}", self.0)
}
}
impl fmt::Display for RelationID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "https://www.openstreetmap.org/relation/{}", self.0)
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum OsmID {
Node(NodeID),
Way(WayID),
Relation(RelationID),
}
impl fmt::Display for OsmID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
OsmID::Node(n) => write!(f, "{}", n),
OsmID::Way(w) => write!(f, "{}", w),
OsmID::Relation(r) => write!(f, "{}", r),
}
}
}
impl OsmID {
pub fn inner(self) -> i64 {
match self {
OsmID::Node(n) => n.0,
OsmID::Way(w) => w.0,
OsmID::Relation(r) => r.0,
}
}
}