Skip to content

Commit

Permalink
Model living streets a bit more carefully.
Browse files Browse the repository at this point in the history
- don't infer parking lanes there
- sidewalks on both side of a one-way
- handle maxspeed with kmph
- no maxspeed on living_street is 20 kmph

still not regenerating maps
  • Loading branch information
dabreegster committed Jul 22, 2020
1 parent 56a892f commit 5d2b770
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
3 changes: 1 addition & 2 deletions convert_osm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ pub fn convert(opts: Options, timer: &mut abstutil::Timer) -> RawMap {
for (id, r) in map.roads.iter_mut() {
if r.osm_tags.contains_key(osm::INFERRED_PARKING)
&& (r.osm_tags.get(osm::HIGHWAY) == Some(&"residential".to_string())
|| r.osm_tags.get(osm::HIGHWAY) == Some(&"tertiary".to_string())
|| r.osm_tags.get(osm::HIGHWAY) == Some(&"living_street".to_string()))
|| r.osm_tags.get(osm::HIGHWAY) == Some(&"tertiary".to_string()))
&& id.osm_way_id % 100 <= pct
{
if r.osm_tags.get("oneway") == Some(&"yes".to_string()) {
Expand Down
2 changes: 1 addition & 1 deletion convert_osm/src/osm_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ fn is_road(tags: &mut Tags) -> bool {
tags.insert(osm::SIDEWALK, "none");
} else if tags.is("oneway", "yes") {
tags.insert(osm::SIDEWALK, "right");
if tags.is(osm::HIGHWAY, "residential") {
if tags.is_any(osm::HIGHWAY, vec!["residential", "living_street"]) {
tags.insert(osm::SIDEWALK, "both");
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions geom/src/speed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ impl Speed {
Speed::meters_per_second(0.44704 * value)
}

pub fn km_per_hour(value: f64) -> Speed {
Speed::meters_per_second(0.277778 * value)
}

pub fn from_dist_time(d: Distance, t: Duration) -> Speed {
Speed::meters_per_second(d.inner_meters() / t.inner_seconds())
}
Expand Down
21 changes: 16 additions & 5 deletions map_model/src/objects/road.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,30 @@ impl Road {

pub(crate) fn speed_limit_from_osm(&self) -> Speed {
if let Some(limit) = self.osm_tags.get(osm::MAXSPEED) {
// TODO handle other units
if limit.ends_with(" mph") {
if let Ok(mph) = limit[0..limit.len() - 4].parse::<f64>() {
return Speed::miles_per_hour(mph);
}
if let Ok(kmph) = limit.parse::<f64>() {
return Speed::km_per_hour(kmph);
}

if let Some(mph) = limit
.strip_suffix(" mph")
.and_then(|x| x.parse::<f64>().ok())
{
return Speed::miles_per_hour(mph);
}

// TODO Handle implicits, like PL:zone30
}

// These're half reasonable guesses. Better to explicitly tag in OSM.
if self.osm_tags.get(osm::HIGHWAY) == Some(&"primary".to_string())
|| self.osm_tags.get(osm::HIGHWAY) == Some(&"secondary".to_string())
{
return Speed::miles_per_hour(40.0);
}
if self.osm_tags.get(osm::HIGHWAY) == Some(&"living_street".to_string()) {
// about 12mph
return Speed::km_per_hour(20.0);
}
Speed::miles_per_hour(20.0)
}

Expand Down

0 comments on commit 5d2b770

Please sign in to comment.