Skip to content

Commit d17d7eb

Browse files
node importance
1 parent 3010ec8 commit d17d7eb

File tree

6 files changed

+50
-20
lines changed

6 files changed

+50
-20
lines changed

include/osr/geojson.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ struct geojson_writer {
179179
{"car", p.is_car_accessible()},
180180
{"bike", p.is_bike_accessible()},
181181
{"foot", p.is_walk_accessible()},
182+
{"importance", p.importance()},
182183
{"is_restricted", w_.r_->node_is_restricted_[n]},
183184
{"is_entrance", p.is_entrance()},
184185
{"is_elevator", p.is_elevator()},

include/osr/routing/profiles/bike_sharing.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ struct bike_sharing {
4747
.is_sidewalk_separate_ = false,
4848
.motor_vehicle_no_ = false,
4949
.has_toll_ = false,
50-
.is_big_street_ = false};
50+
.is_big_street_ = false,
51+
.importance_ = 0};
5152

5253
static constexpr auto const kAdditionalNodeProperties =
5354
node_properties{.from_level_ = 0,
@@ -58,7 +59,8 @@ struct bike_sharing {
5859
.is_entrance_ = false,
5960
.is_multi_level_ = false,
6061
.is_parking_ = false,
61-
.to_level_ = 0};
62+
.to_level_ = 0,
63+
.importance_ = 0};
6264

6365
enum class node_type : std::uint8_t {
6466
kInitialFoot,

include/osr/routing/profiles/car_sharing.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ struct car_sharing {
4747
.is_sidewalk_separate_ = false,
4848
.motor_vehicle_no_ = false,
4949
.has_toll_ = false,
50-
.is_big_street_ = false};
50+
.is_big_street_ = false,
51+
.importance_ = 0};
5152

5253
static constexpr auto const kAdditionalNodeProperties =
5354
node_properties{.from_level_ = 0,
@@ -58,7 +59,8 @@ struct car_sharing {
5859
.is_entrance_ = false,
5960
.is_multi_level_ = false,
6061
.is_parking_ = false,
61-
.to_level_ = 0};
62+
.to_level_ = 0,
63+
.importance_ = 0};
6264

6365
enum class node_type : std::uint8_t {
6466
kInitialFoot,

include/osr/ways.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct way_properties {
103103
bool motor_vehicle_no_ : 1;
104104
bool has_toll_ : 1;
105105
bool is_big_street_ : 1;
106+
std::uint8_t importance_ : 3; // only used during extract
106107
};
107108

108109
static_assert(sizeof(way_properties) == 4);
@@ -115,6 +116,7 @@ struct node_properties {
115116
constexpr bool is_multi_level() const { return is_multi_level_; }
116117
constexpr bool is_entrance() const { return is_entrance_; }
117118
constexpr bool is_parking() const { return is_parking_; }
119+
constexpr std::uint8_t importance() const { return importance_; }
118120

119121
constexpr level_t from_level() const { return level_t{from_level_}; }
120122
constexpr level_t to_level() const { return level_t{to_level_}; }
@@ -142,6 +144,7 @@ struct node_properties {
142144
bool is_parking_ : 1;
143145

144146
std::uint8_t to_level_ : 5;
147+
std::uint8_t importance_ : 3;
145148
};
146149

147150
static_assert(sizeof(node_properties) == 3);
@@ -152,7 +155,7 @@ struct ways {
152155
void add_restriction(std::vector<resolved_restriction>&);
153156
void compute_big_street_neighbors();
154157
void connect_ways();
155-
void build_components();
158+
void build_components_and_importance();
156159

157160
std::optional<way_idx_t> find_way(osm_way_idx_t const i) {
158161
auto const it = std::lower_bound(begin(way_osm_idx_), end(way_osm_idx_), i);

src/extract.cc

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,38 @@ bool is_number(std::string_view s) {
6060
utl::all_of(s, [](char const c) { return std::isdigit(c); });
6161
}
6262

63-
bool is_big_street(tags const& t) {
63+
std::uint8_t get_importance(tags const& t) {
6464
switch (cista::hash(t.highway_)) {
65-
case cista::hash("motorway"):
66-
case cista::hash("motorway_link"):
67-
case cista::hash("trunk"):
68-
case cista::hash("trunk_link"):
69-
case cista::hash("primary"):
70-
case cista::hash("primary_link"):
65+
case cista::hash("pedestrian"):
66+
case cista::hash("busway"):
67+
case cista::hash("footway"):
68+
case cista::hash("cycleway"):
69+
case cista::hash("bridleway"):
70+
case cista::hash("steps"):
71+
case cista::hash("corridor"):
72+
case cista::hash("path"): return 0;
73+
case cista::hash("track"): return 1;
74+
case cista::hash("living_street"):
75+
case cista::hash("service"): return 2;
76+
case cista::hash("residential"): return 3;
77+
case cista::hash("road"): return 4;
78+
case cista::hash("unclassified"):
79+
case cista::hash("tertiary"):
80+
case cista::hash("tertiary_link"): return 5;
7181
case cista::hash("secondary"):
7282
case cista::hash("secondary_link"):
73-
case cista::hash("tertiary"):
74-
case cista::hash("tertiary_link"):
75-
case cista::hash("unclassified"): return true;
76-
default: return false;
83+
case cista::hash("primary"):
84+
case cista::hash("primary_link"): return 6;
85+
case cista::hash("trunk"):
86+
case cista::hash("trunk_link"):
87+
case cista::hash("motorway"):
88+
case cista::hash("motorway_link"): return 7;
89+
default: return 4;
7790
}
7891
}
7992

93+
bool is_big_street(std::uint8_t const importance) { return importance > 4; }
94+
8095
speed_limit get_speed_limit(tags const& t) {
8196
if (is_number(t.max_speed_) /* TODO: support units (kmh/mph) */) {
8297
return get_speed_limit(
@@ -140,7 +155,8 @@ way_properties get_way_properties(tags const& t) {
140155
p.motor_vehicle_no_ =
141156
(t.motor_vehicle_ == "no"sv) || (t.vehicle_ == override::kBlacklist);
142157
p.has_toll_ = t.toll_;
143-
p.is_big_street_ = is_big_street(t);
158+
p.importance_ = get_importance(t);
159+
p.is_big_street_ = is_big_street(p.importance_);
144160
return p;
145161
}
146162

@@ -157,6 +173,7 @@ std::pair<node_properties, level_bits_t> get_node_properties(tags const& t) {
157173
p.is_multi_level_ = is_multi;
158174
p.is_parking_ = t.is_parking_;
159175
p.to_level_ = to_idx(to);
176+
p.importance_ = 0;
160177
return {p, t.level_bits_};
161178
}
162179

@@ -581,7 +598,6 @@ void extract(bool const with_platforms,
581598
w.sync();
582599

583600
w.connect_ways();
584-
w.build_components();
585601

586602
auto r = std::vector<resolved_restriction>{};
587603
{
@@ -600,6 +616,7 @@ void extract(bool const with_platforms,
600616
pt->update(pt->in_high_);
601617
}
602618

619+
w.build_components_and_importance();
603620
w.add_restriction(r);
604621

605622
utl::sort(w.r_->multi_level_elevators_);

src/ways.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ways::ways(std::filesystem::path p, cista::mmap::protection const mode)
2525
mm_vec<std::uint64_t>(mm("way_has_conditional_access_no"))},
2626
way_conditional_access_no_{mm("way_conditional_access_no")} {}
2727

28-
void ways::build_components() {
28+
void ways::build_components_and_importance() {
2929
auto q = hash_set<way_idx_t>{};
3030
auto flood_fill = [&](way_idx_t const way_idx, component_idx_t const c) {
3131
assert(q.empty());
@@ -34,6 +34,9 @@ void ways::build_components() {
3434
auto const next = *q.begin();
3535
q.erase(q.begin());
3636
for (auto const n : r_->way_nodes_[next]) {
37+
r_->node_properties_[n].importance_ =
38+
std::max(r_->node_properties_[n].importance_,
39+
r_->way_properties_[next].importance_);
3740
for (auto const w : r_->node_ways_[n]) {
3841
auto& wc = r_->way_component_[w];
3942
if (wc == component_idx_t::invalid()) {
@@ -46,7 +49,9 @@ void ways::build_components() {
4649
};
4750

4851
auto pt = utl::get_active_progress_tracker_or_activate("osr");
49-
pt->status("Build components").in_high(n_ways()).out_bounds(75, 90);
52+
pt->status("Build components and importance")
53+
.in_high(n_ways())
54+
.out_bounds(75, 90);
5055

5156
auto next_component_idx = component_idx_t{0U};
5257
r_->way_component_.resize(n_ways(), component_idx_t::invalid());

0 commit comments

Comments
 (0)