From 4ac8c6e30bfd527b079b8da1e8e66fdca99665f6 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 6 May 2021 14:20:00 -0700 Subject: [PATCH] Tighten the GDAL flag guarding in the importer. This removes some noise from 'cargo check' and is also a step towards running the importer in a Docker container without having to rebuild it there. #326 --- importer/src/main.rs | 35 ++++++++++---------------------- importer/src/seattle.rs | 1 - importer/src/soundcast/popdat.rs | 13 +++++++++++- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/importer/src/main.rs b/importer/src/main.rs index 6dfca2d00c..d611c756a2 100644 --- a/importer/src/main.rs +++ b/importer/src/main.rs @@ -16,7 +16,6 @@ mod berlin; mod configuration; mod generic; mod seattle; -#[cfg(feature = "scenarios")] mod soundcast; mod uk; mod utils; @@ -155,28 +154,17 @@ impl Job { .collect() }; - let (maybe_popdat, maybe_huge_map, maybe_zoning_parcels) = - if self.scenario && self.city == CityName::seattle() { - #[cfg(feature = "scenarios")] - { - let (popdat, huge_map) = seattle::ensure_popdat_exists(timer, config).await; - // Just assume --raw has been called... - let shapes: kml::ExtraShapes = abstio::read_binary( - CityName::seattle().input_path("zoning_parcels.bin"), - timer, - ); - (Some(popdat), Some(huge_map), Some(shapes)) - } - - #[cfg(not(feature = "scenarios"))] - { - panic!("Can't do --scenario without the scenarios feature compiled in"); - // Nonsense to make the type-checker work - (Some(true), Some(true), Some(true)) - } - } else { - (None, None, None) - }; + let (maybe_popdat, maybe_huge_map, maybe_zoning_parcels) = if self.scenario + && self.city == CityName::seattle() + { + let (popdat, huge_map) = seattle::ensure_popdat_exists(timer, config).await; + // Just assume --raw has been called... + let shapes: kml::ExtraShapes = + abstio::read_binary(CityName::seattle().input_path("zoning_parcels.bin"), timer); + (Some(popdat), Some(huge_map), Some(shapes)) + } else { + (None, None, None) + }; for name in names { if self.osm_to_raw { @@ -240,7 +228,6 @@ impl Job { }; if self.scenario { - #[cfg(feature = "scenarios")] if self.city == CityName::seattle() { timer.start(format!("scenario for {}", name.describe())); let scenario = soundcast::make_weekday_scenario( diff --git a/importer/src/seattle.rs b/importer/src/seattle.rs index 9890186502..3f70c67fec 100644 --- a/importer/src/seattle.rs +++ b/importer/src/seattle.rs @@ -153,7 +153,6 @@ pub async fn osm_to_raw(name: &str, timer: &mut Timer<'_>, config: &ImporterConf } /// Download and pre-process data needed to generate Seattle scenarios. -#[cfg(feature = "scenarios")] pub async fn ensure_popdat_exists( timer: &mut Timer<'_>, config: &ImporterConfiguration, diff --git a/importer/src/soundcast/popdat.rs b/importer/src/soundcast/popdat.rs index a4d30b7ce6..0fdbb2294f 100644 --- a/importer/src/soundcast/popdat.rs +++ b/importer/src/soundcast/popdat.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use abstio::{CityName, FileWithProgress}; use abstutil::{prettyprint_usize, Counter, Timer}; -use geom::{Distance, Duration, FindClosest, LonLat, Time}; +use geom::{Distance, Duration, LonLat, Time}; use kml::{ExtraShape, ExtraShapes}; use map_model::{osm, Map}; use sim::{OrigPersonID, TripMode, TripPurpose}; @@ -113,10 +113,13 @@ fn import_trips(huge_map: &Map, timer: &mut Timer) -> Vec { // TODO Do we also need the zone ID, or is parcel ID globally unique? // Keyed by parcel ID +#[cfg(feature = "scenarios")] fn import_parcels( huge_map: &Map, timer: &mut Timer, ) -> (HashMap, BTreeMap) { + use geom::FindClosest; + // TODO I really just want to do polygon containment with a quadtree. FindClosest only does // line-string stuff right now, which'll be weird for the last->first pt line and stuff. let mut closest_bldg: FindClosest = FindClosest::new(huge_map.get_bounds()); @@ -220,6 +223,14 @@ fn import_parcels( (result, shapes) } +#[cfg(not(feature = "scenarios"))] +fn import_parcels( + _: &Map, + _: &mut Timer, +) -> (HashMap, BTreeMap) { + panic!("Can't import_parcels for popdat.bin without the scenarios feature (GDAL dependency)"); +} + // From https://github.com/psrc/soundcast/wiki/Outputs#trip-file-_triptsv, opurp and dpurp fn get_purpose(code: &str) -> TripPurpose { match code {