From 18a5a2f2f8bda7131a221d09b08a5fbdd3da3dc9 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 16 Sep 2018 16:44:59 -0700 Subject: [PATCH] remove parcels too far from sidewalks --- docs/TODO_phase1.md | 2 -- map_model/src/make/buildings.rs | 2 +- map_model/src/make/mod.rs | 2 ++ map_model/src/make/parcels.rs | 55 +++++++++++++++++++++++++++++++++ map_model/src/map.rs | 13 ++------ 5 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 map_model/src/make/parcels.rs diff --git a/docs/TODO_phase1.md b/docs/TODO_phase1.md index 15a8507d74..3166026e7f 100644 --- a/docs/TODO_phase1.md +++ b/docs/TODO_phase1.md @@ -12,8 +12,6 @@ - https://data-seattlecitygis.opendata.arcgis.com/datasets/curb-ramps - high quality thick roads: https://seattlecitygis.maps.arcgis.com/apps/webappviewer/index.html?id=86cb6824307c4d63b8e180ebcff58ce2 -- trim parcels that're nowhere near roads (aka, the bbox is kinda wrong) - - maybe also the time to split into different lane types? what's similar/not between them? - graph querying? - rendering (and other UI/editor interactions)? diff --git a/map_model/src/make/buildings.rs b/map_model/src/make/buildings.rs index ea32ac5b3c..98e5d1e933 100644 --- a/map_model/src/make/buildings.rs +++ b/map_model/src/make/buildings.rs @@ -36,7 +36,7 @@ pub(crate) fn make_all_buildings( let line = trim_front_path(&points, Line::new(bldg_center.into(), sidewalk_pt)); // Trim buildings that are too far away from their sidewalk - if line.length() > 200.0 * si::M { + if line.length() > 100.0 * si::M { continue; } diff --git a/map_model/src/make/mod.rs b/map_model/src/make/mod.rs index 60027f5754..f095d63214 100644 --- a/map_model/src/make/mod.rs +++ b/map_model/src/make/mod.rs @@ -1,6 +1,7 @@ mod buildings; mod bus_stops; mod lanes; +mod parcels; mod sidewalk_finder; mod trim_lines; mod turns; @@ -8,5 +9,6 @@ mod turns; pub(crate) use self::buildings::make_all_buildings; pub(crate) use self::bus_stops::make_bus_stops; pub(crate) use self::lanes::get_lane_specs; +pub(crate) use self::parcels::make_all_parcels; pub(crate) use self::trim_lines::trim_lines; pub(crate) use self::turns::make_all_turns; diff --git a/map_model/src/make/parcels.rs b/map_model/src/make/parcels.rs new file mode 100644 index 0000000000..36fc12a9f3 --- /dev/null +++ b/map_model/src/make/parcels.rs @@ -0,0 +1,55 @@ +use dimensioned::si; +use geom::{Bounds, HashablePt2D, Line, Pt2D}; +use geometry; +use make::sidewalk_finder::find_sidewalk_points; +use raw_data; +use std::collections::HashSet; +use {Lane, Parcel, ParcelID}; + +pub(crate) fn make_all_parcels( + results: &mut Vec, + input: &Vec, + bounds: &Bounds, + lanes: &Vec, +) { + let mut pts_per_parcel: Vec> = Vec::new(); + let mut center_per_parcel: Vec = Vec::new(); + let mut query: HashSet = HashSet::new(); + for p in input { + let pts = p + .points + .iter() + .map(|coord| Pt2D::from_gps(coord, bounds)) + .collect(); + let center: HashablePt2D = geometry::center(&pts).into(); + pts_per_parcel.push(pts); + center_per_parcel.push(center); + query.insert(center); + } + + let sidewalk_pts = find_sidewalk_points(query, lanes); + + for (idx, center) in center_per_parcel.into_iter().enumerate() { + let (sidewalk, dist_along) = sidewalk_pts[¢er]; + let (sidewalk_pt, _) = lanes[sidewalk.0].dist_along(dist_along); + let line = Line::new(center.into(), sidewalk_pt); + // Trim parcels that are too far away from the nearest sidewalk + if line.length() > 100.0 * si::M { + continue; + } + + let id = ParcelID(results.len()); + results.push(Parcel { + id, + points: pts_per_parcel[idx].clone(), + block: input[idx].block, + }); + } + let discarded = input.len() - results.len(); + if discarded > 0 { + println!( + "Discarded {} parcels that weren't close enough to a sidewalk", + discarded + ); + } +} diff --git a/map_model/src/map.rs b/map_model/src/map.rs index 393dba0f05..1664426c82 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -185,16 +185,9 @@ impl Map { } } - for (idx, p) in data.parcels.iter().enumerate() { - m.parcels.push(Parcel { - id: ParcelID(idx), - points: p - .points - .iter() - .map(|coord| Pt2D::from_gps(coord, &bounds)) - .collect(), - block: p.block, - }); + { + let _guard = flame::start_guard(format!("make {} parcels", data.parcels.len())); + make::make_all_parcels(&mut m.parcels, &data.parcels, &bounds, &m.lanes); } for (idx, a) in data.areas.iter().enumerate() {