Skip to content

Commit

Permalink
Next steps on snapping cycleways / modelling separators. #330
Browse files Browse the repository at this point in the history
- Only snap cycleways with explicitly tagged separators
- When collapsing intersections, preserve the OSM ID of the longer way
  • Loading branch information
dabreegster committed Jul 29, 2021
1 parent 1bda933 commit 7fbd8ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions map_model/src/make/collapse_intersections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ fn is_cycleway(road: &RawRoad, raw: &RawMap) -> bool {
pub fn collapse_intersection(raw: &mut RawMap, i: NodeID) {
let roads = raw.roads_per_intersection(i);
assert_eq!(roads.len(), 2);
let r1 = roads[0];
let r2 = roads[1];
let mut r1 = roads[0];
let mut r2 = roads[1];

// We'll keep r1's ID, so it's a little more convenient for debugging to guarantee r1 is the
// longer piece.
if raw.roads[&r1].length() < raw.roads[&r2].length() {
std::mem::swap(&mut r1, &mut r2);
}

// Skip loops; they break. Easiest way to detect is see how many total vertices we've got.
let mut endpts = BTreeSet::new();
Expand Down
10 changes: 9 additions & 1 deletion map_model/src/make/snappy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ pub fn snap_cycleways(map: &mut RawMap) {

let mut cycleways = Vec::new();
for (id, road) in &map.roads {
if road.is_cycleway(&map.config) {
// Because there are so many false positives with snapping, only start with cycleways
// explicitly tagged with
// https://wiki.openstreetmap.org/wiki/Proposed_features/cycleway:separation
if road.is_cycleway(&map.config)
&& (road.osm_tags.contains_key("separation:left")
|| road.osm_tags.contains_key("separation:right"))
{
let (center, total_width) = road.get_geometry(*id, &map.config).unwrap();
cycleways.push(Cycleway {
id: *id,
Expand Down Expand Up @@ -152,6 +158,8 @@ fn v1(
let mut matches_here = Vec::new();
loop {
let (pt, cycleway_angle) = cycleway.center.must_dist_along(dist);
// TODO In the common case, only the separation between the cyclepath and main traffic
// will be tagged. So we could just look in that direction...
let perp_line = Line::must_new(
pt.project_away(cycleway_half_width, cycleway_angle.rotate_degs(90.0)),
pt.project_away(cycleway_half_width, cycleway_angle.rotate_degs(-90.0)),
Expand Down

0 comments on commit 7fbd8ae

Please sign in to comment.