Skip to content

Commit

Permalink
Use simple Rust code to specify map importing config, instead of conf… (
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster authored Nov 17, 2021
1 parent 27894c0 commit 68d9616
Show file tree
Hide file tree
Showing 99 changed files with 402 additions and 1,926 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod import_grid2demand;
mod import_scenario;
mod one_step_import;
mod osm2lanes;
mod pick_geofabrik;

use anyhow::Result;
use structopt::StructOpt;
Expand Down Expand Up @@ -255,7 +254,7 @@ async fn main() -> Result<()> {
output,
} => generate_houses::run(map, num_required, rng_seed, output),
Command::PickGeofabrik { input } => {
println!("{}", pick_geofabrik::run(input).await?)
println!("{}", importer::pick_geofabrik(input).await?)
}
Command::OneStepImport {
geojson_path,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/one_step_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub async fn run(
.await?;
} else {
println!("Figuring out what Geofabrik file contains your boundary");
let url = crate::pick_geofabrik::run("boundary0.poly".to_string()).await?;
let url = importer::pick_geofabrik("boundary0.poly".to_string()).await?;

let pbf = city.input_path(format!("osm/{}.pbf", abstutil::basename(&url)));
osm = city.input_path(format!("osm/{}.osm", name));
Expand Down
12 changes: 9 additions & 3 deletions convert_osm/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ pub struct OsmExtract {
pub crosswalks: HashSet<HashablePt2D>,
}

pub fn extract_osm(map: &mut RawMap, opts: &Options, timer: &mut Timer) -> OsmExtract {
let mut doc = crate::reader::read(&opts.osm_input, &map.gps_bounds, timer).unwrap();
pub fn extract_osm(
map: &mut RawMap,
osm_input_path: &str,
clip_path: Option<String>,
opts: &Options,
timer: &mut Timer,
) -> OsmExtract {
let mut doc = crate::reader::read(osm_input_path, &map.gps_bounds, timer).unwrap();

// TODO Hacks to override OSM data. There's no problem upstream, but we want to accomplish
// various things for A/B Street.
Expand All @@ -44,7 +50,7 @@ pub fn extract_osm(map: &mut RawMap, opts: &Options, timer: &mut Timer) -> OsmEx
way.tags.insert("junction", "intersection");
}

if opts.clip.is_none() {
if clip_path.is_none() {
// Use the boundary from .osm.
map.gps_bounds = doc.gps_bounds.clone();
map.boundary_polygon = map.gps_bounds.to_bounds().get_rectangle();
Expand Down
21 changes: 12 additions & 9 deletions convert_osm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ pub mod reader;
mod split_ways;
mod transit;

/// Configures the creation of a RawMap from OSM and other input data.
pub struct Options {
pub osm_input: String,
pub name: MapName,

/// The path to an osmosis boundary polygon. Highly recommended.
pub clip: Option<String>,
pub map_config: MapConfig,

pub onstreet_parking: OnstreetParking,
Expand Down Expand Up @@ -80,16 +76,23 @@ pub enum PrivateOffstreetParking {
// TODO Based on the number of residents?
}

pub fn convert(opts: Options, timer: &mut abstutil::Timer) -> RawMap {
let mut map = RawMap::blank(opts.name.clone());
if let Some(ref path) = opts.clip {
/// Create a RawMap from OSM and other input data.
pub fn convert(
osm_input_path: String,
name: MapName,
clip_path: Option<String>,
opts: Options,
timer: &mut Timer,
) -> RawMap {
let mut map = RawMap::blank(name.clone());
if let Some(ref path) = clip_path {
let pts = LonLat::read_osmosis_polygon(path).unwrap();
let gps_bounds = GPSBounds::from(pts.clone());
map.boundary_polygon = Ring::must_new(gps_bounds.convert(&pts)).into_polygon();
map.gps_bounds = gps_bounds;
}

let extract = extract::extract_osm(&mut map, &opts, timer);
let extract = extract::extract_osm(&mut map, &osm_input_path, clip_path, &opts, timer);
let (amenities, crosswalks, pt_to_road) = split_ways::split_up_roads(&mut map, extract, timer);
clip::clip_map(&mut map, timer);

Expand Down
Loading

0 comments on commit 68d9616

Please sign in to comment.