diff --git a/convert_osm/src/lib.rs b/convert_osm/src/lib.rs index bb9769aff0..1b667f9194 100644 --- a/convert_osm/src/lib.rs +++ b/convert_osm/src/lib.rs @@ -7,7 +7,7 @@ use anyhow::Result; use abstio::MapName; use abstutil::{Tags, Timer}; -use geom::{Distance, FindClosest, GPSBounds, LonLat, Pt2D, Ring}; +use geom::{Distance, FindClosest, GPSBounds, LonLat, PolyLine, Pt2D, Ring}; use map_model::raw::RawMap; use map_model::{osm, raw, Amenity, MapConfig}; use serde::{Deserialize, Serialize}; @@ -116,6 +116,9 @@ pub fn convert(opts: Options, timer: &mut abstutil::Timer) -> RawMap { if let Some(ref path) = opts.elevation { use_elevation(&mut map, path, timer); } + if false { + generate_elevation_queries(&map).unwrap(); + } if let Some(ref path) = opts.extra_buildings { add_extra_buildings(&mut map, path).unwrap(); } @@ -158,6 +161,38 @@ fn use_elevation(map: &mut RawMap, path: &str, timer: &mut Timer) { timer.stop("apply elevation data to intersections"); } +fn generate_elevation_queries(map: &RawMap) -> Result<()> { + use std::fs::File; + use std::io::Write; + + let mut f = File::create("elevation_queries")?; + for r in map.roads.values() { + // TODO Handle cul-de-sacs + if let Ok(pl) = PolyLine::new(r.center_points.clone()) { + // Sample points every meter along the road + let mut pts = Vec::new(); + let mut dist = Distance::ZERO; + while dist <= pl.length() { + let (pt, _) = pl.dist_along(dist).unwrap(); + pts.push(pt); + dist += Distance::meters(1.0); + } + // Always ask for the intersection + if *pts.last().unwrap() != pl.last_pt() { + pts.push(pl.last_pt()); + } + for (idx, gps) in map.gps_bounds.convert_back(&pts).into_iter().enumerate() { + write!(f, "{},{}", gps.x(), gps.y())?; + if idx != pts.len() - 1 { + write!(f, ",")?; + } + } + writeln!(f)?; + } + } + Ok(()) +} + fn add_extra_buildings(map: &mut RawMap, path: &str) -> Result<()> { // TODO Refactor code that just extracts polygons from geojson. let mut polygons = Vec::new(); diff --git a/importer/src/main.rs b/importer/src/main.rs index d1ef1ab2db..7ca0a4bffc 100644 --- a/importer/src/main.rs +++ b/importer/src/main.rs @@ -1,8 +1,6 @@ //! It's assumed that the importer is run with the current directory as the project repository; aka //! `./data/` and `./importer/config` must exist. -#[macro_use] -extern crate anyhow; #[macro_use] extern crate log;