mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 12:12:00 +03:00
keep the first contiguous run of stops inside the boundary for #190
This commit is contained in:
parent
7a1081971d
commit
d94c03392f
@ -291,8 +291,14 @@ pub fn extract_osm(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if tags.is("type", "route") {
|
} else if tags.is("type", "route") {
|
||||||
map.bus_routes
|
map.bus_routes.extend(extract_route(
|
||||||
.extend(extract_route(&tags, rel, &doc, &id_to_way, &map.gps_bounds));
|
&tags,
|
||||||
|
rel,
|
||||||
|
&doc,
|
||||||
|
&id_to_way,
|
||||||
|
&map.gps_bounds,
|
||||||
|
&map.boundary_polygon,
|
||||||
|
));
|
||||||
} else if tags.is("type", "multipolygon") && tags.contains_key("amenity") {
|
} else if tags.is("type", "multipolygon") && tags.contains_key("amenity") {
|
||||||
let name = tags
|
let name = tags
|
||||||
.get("name")
|
.get("name")
|
||||||
@ -654,6 +660,7 @@ fn extract_route(
|
|||||||
doc: &osm_xml::OSM,
|
doc: &osm_xml::OSM,
|
||||||
id_to_way: &HashMap<i64, Vec<Pt2D>>,
|
id_to_way: &HashMap<i64, Vec<Pt2D>>,
|
||||||
gps_bounds: &GPSBounds,
|
gps_bounds: &GPSBounds,
|
||||||
|
boundary: &Polygon,
|
||||||
) -> Option<RawBusRoute> {
|
) -> Option<RawBusRoute> {
|
||||||
let full_name = tags.get("name")?.clone();
|
let full_name = tags.get("name")?.clone();
|
||||||
let short_name = tags
|
let short_name = tags
|
||||||
@ -664,12 +671,15 @@ fn extract_route(
|
|||||||
"bus" => true,
|
"bus" => true,
|
||||||
"light_rail" => false,
|
"light_rail" => false,
|
||||||
x => {
|
x => {
|
||||||
println!(
|
if x != "road" && x != "bicycle" {
|
||||||
"Skipping route {} of unknown type {}: {}",
|
// TODO Handle these at some point
|
||||||
full_name,
|
println!(
|
||||||
x,
|
"Skipping route {} of unknown type {}: {}",
|
||||||
rel_url(rel.id)
|
full_name,
|
||||||
);
|
x,
|
||||||
|
rel_url(rel.id)
|
||||||
|
);
|
||||||
|
}
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -727,7 +737,30 @@ fn extract_route(
|
|||||||
stop.ped_pos = Some(pt);
|
stop.ped_pos = Some(pt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if stops.len() < 2 {
|
|
||||||
|
// Remove stops that're out of bounds. Once we find the first in-bound point, keep all in-bound
|
||||||
|
// stops and halt as soon as we go out of bounds again. If a route happens to dip in and out of
|
||||||
|
// the boundary, we don't want to leave gaps.
|
||||||
|
let mut keep_stops = Vec::new();
|
||||||
|
let orig_num = stops.len();
|
||||||
|
for stop in stops {
|
||||||
|
if boundary.contains_pt(stop.vehicle_pos) {
|
||||||
|
keep_stops.push(stop);
|
||||||
|
} else {
|
||||||
|
if !keep_stops.is_empty() {
|
||||||
|
// That's the end of them
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!(
|
||||||
|
"Kept {} / {} contiguous stops from route {}",
|
||||||
|
keep_stops.len(),
|
||||||
|
orig_num,
|
||||||
|
rel_url(rel.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if keep_stops.len() < 2 {
|
||||||
// Routes with only 1 stop are pretty much useless, and it makes border matching quite
|
// Routes with only 1 stop are pretty much useless, and it makes border matching quite
|
||||||
// confusing.
|
// confusing.
|
||||||
return None;
|
return None;
|
||||||
@ -738,7 +771,7 @@ fn extract_route(
|
|||||||
short_name,
|
short_name,
|
||||||
is_bus,
|
is_bus,
|
||||||
osm_rel_id: rel.id,
|
osm_rel_id: rel.id,
|
||||||
stops,
|
stops: keep_stops,
|
||||||
border_start: None,
|
border_start: None,
|
||||||
border_end: None,
|
border_end: None,
|
||||||
all_pts,
|
all_pts,
|
||||||
|
@ -220,11 +220,11 @@ impl Matcher {
|
|||||||
.ok_or("light rail missing platform")?
|
.ok_or("light rail missing platform")?
|
||||||
.to_hashable(),
|
.to_hashable(),
|
||||||
)
|
)
|
||||||
.ok_or("sidewalk didnt match")?;
|
.ok_or("sidewalk for light rail didnt match")?;
|
||||||
let driving_pos = *self
|
let driving_pos = *self
|
||||||
.light_rail_pts
|
.light_rail_pts
|
||||||
.get(&stop.vehicle_pos.to_hashable())
|
.get(&stop.vehicle_pos.to_hashable())
|
||||||
.ok_or("driving didnt match")?;
|
.ok_or("driving for light rail didnt match")?;
|
||||||
return Ok((sidewalk_pos, driving_pos));
|
return Ok((sidewalk_pos, driving_pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ impl Matcher {
|
|||||||
let orig_driving_pos = *self
|
let orig_driving_pos = *self
|
||||||
.bus_pts
|
.bus_pts
|
||||||
.get(&stop.vehicle_pos.to_hashable())
|
.get(&stop.vehicle_pos.to_hashable())
|
||||||
.ok_or("driving didnt match")?;
|
.ok_or("driving for bus didnt match")?;
|
||||||
let sidewalk = map
|
let sidewalk = map
|
||||||
.get_parent(orig_driving_pos.lane())
|
.get_parent(orig_driving_pos.lane())
|
||||||
.find_closest_lane(orig_driving_pos.lane(), vec![LaneType::Sidewalk])?;
|
.find_closest_lane(orig_driving_pos.lane(), vec![LaneType::Sidewalk])?;
|
||||||
|
Loading…
Reference in New Issue
Block a user