mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 15:02:59 +03:00
Emit a file with points to query for an elevation service. #82
This commit is contained in:
parent
5577021ee5
commit
737019a9ec
@ -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();
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user