From 34b41a909ed4f3aed2ef22d3a2083735f9dc891b Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sat, 24 Oct 2020 14:19:22 -0700 Subject: [PATCH] Optionally keep building OSM tags. Display in info panels and the new viewer, when present. Don't keep the tags by default. File size increase from the empty map is negligible. --- abstutil/src/collections.rs | 4 +++ data/MANIFEST.json | 52 +++++++++++++++---------------- game/src/devtools/osm_viewer.rs | 16 ++++++++++ game/src/info/building.rs | 12 +++++++ importer/src/main.rs | 16 ++++++++-- importer/src/seattle.rs | 2 +- importer/src/utils.rs | 9 ++++-- map_model/src/make/buildings.rs | 6 ++++ map_model/src/make/mod.rs | 12 +++++-- map_model/src/map.rs | 2 +- map_model/src/objects/building.rs | 2 ++ map_tests/src/main.rs | 2 +- 12 files changed, 98 insertions(+), 37 deletions(-) diff --git a/abstutil/src/collections.rs b/abstutil/src/collections.rs index 909360e6b6..efa27b1bd0 100644 --- a/abstutil/src/collections.rs +++ b/abstutil/src/collections.rs @@ -240,6 +240,10 @@ impl Tags { self.0.remove(k) } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + // TODO Really just iter() pub fn inner(&self) -> &BTreeMap { &self.0 diff --git a/data/MANIFEST.json b/data/MANIFEST.json index 40ca6f5082..8b20de85ef 100644 --- a/data/MANIFEST.json +++ b/data/MANIFEST.json @@ -397,56 +397,56 @@ "dropbox_url": "https://www.dropbox.com/s/ibvdbbdjdi233mr/seattle.bin.zip?dl=0" }, "data/system/maps/ballard.bin": { - "checksum": "cf1ee807cf67453ce0d92fd7ae2353a0", - "dropbox_url": "https://www.dropbox.com/s/xxdgxmjg7h3bine/ballard.bin.zip?dl=0" + "checksum": "f53ea69b1b8c62d611795d748e1e67ca", + "dropbox_url": "https://www.dropbox.com/s/gkhrsi1adi905lp/ballard.bin.zip?dl=0" }, "data/system/maps/berlin_center.bin": { - "checksum": "0e1e361ee45589810b44b7d69f08ebd5", - "dropbox_url": "https://www.dropbox.com/s/ku1n7i6e3mv1tu5/berlin_center.bin.zip?dl=0" + "checksum": "e9474395f8a4f5f13941593745c64986", + "dropbox_url": "https://www.dropbox.com/s/93chwc62k74n8u3/berlin_center.bin.zip?dl=0" }, "data/system/maps/downtown.bin": { - "checksum": "dfb1e44a802fa0476c5a9388bab19e01", - "dropbox_url": "https://www.dropbox.com/s/ko3le915rbkso2o/downtown.bin.zip?dl=0" + "checksum": "bb6cc3bb5f255e6b86bf0086051be4b3", + "dropbox_url": "https://www.dropbox.com/s/mv0h91a6slgbihd/downtown.bin.zip?dl=0" }, "data/system/maps/huge_seattle.bin": { - "checksum": "34c0f7b5e098f30a50eea2709c80e251", - "dropbox_url": "https://www.dropbox.com/s/942dw52tw2kobr0/huge_seattle.bin.zip?dl=0" + "checksum": "b324d48a02b46251f73e32f88bfd8266", + "dropbox_url": "https://www.dropbox.com/s/ltvvev9gm0radpi/huge_seattle.bin.zip?dl=0" }, "data/system/maps/krakow_center.bin": { - "checksum": "4d883a4e9bf320746989dbcf8c3ac1c8", - "dropbox_url": "https://www.dropbox.com/s/cc0o6xlmqidexvg/krakow_center.bin.zip?dl=0" + "checksum": "67f1d4a270a5b20daad66695deb343cf", + "dropbox_url": "https://www.dropbox.com/s/r0048aj3cjkgupt/krakow_center.bin.zip?dl=0" }, "data/system/maps/lakeslice.bin": { - "checksum": "54830adc049dc3438d6a68c8191510e4", - "dropbox_url": "https://www.dropbox.com/s/hmb226uzr9hewqz/lakeslice.bin.zip?dl=0" + "checksum": "54942cf869156b4967929e099d502980", + "dropbox_url": "https://www.dropbox.com/s/en5g7zzv6ynv4zu/lakeslice.bin.zip?dl=0" }, "data/system/maps/montlake.bin": { - "checksum": "6cdf3d134bc3714ca2b9b536a7b11517", - "dropbox_url": "https://www.dropbox.com/s/3sq35evuakzr7oj/montlake.bin.zip?dl=0" + "checksum": "b96bd0f0116b52e9a091f108c1113230", + "dropbox_url": "https://www.dropbox.com/s/7r7ivpxs1kiea4o/montlake.bin.zip?dl=0" }, "data/system/maps/south_seattle.bin": { - "checksum": "a789ebb3f6d55e98069acad329c167a5", - "dropbox_url": "https://www.dropbox.com/s/2y1qqa7sxekrpwa/south_seattle.bin.zip?dl=0" + "checksum": "9b008200ff3eb1270a96c0af4f7fa10f", + "dropbox_url": "https://www.dropbox.com/s/5l2z7xd57visyqf/south_seattle.bin.zip?dl=0" }, "data/system/maps/southbank.bin": { - "checksum": "7aa6c94501fd745cbe9122702d46ff0c", - "dropbox_url": "https://www.dropbox.com/s/67zc7x6gdyqtomg/southbank.bin.zip?dl=0" + "checksum": "8f83d037ab04bcfdfcb96a0fb2d3ccf7", + "dropbox_url": "https://www.dropbox.com/s/ldsydqidids6fiz/southbank.bin.zip?dl=0" }, "data/system/maps/tel_aviv.bin": { - "checksum": "839283d1d221db99227645a462f6dc68", - "dropbox_url": "https://www.dropbox.com/s/sz1xf73f914twz5/tel_aviv.bin.zip?dl=0" + "checksum": "d619cfb34bbd92da5e560d62992cf4f5", + "dropbox_url": "https://www.dropbox.com/s/khnpq20pq3qapyo/tel_aviv.bin.zip?dl=0" }, "data/system/maps/udistrict.bin": { - "checksum": "a547d5d8694371c2c6f9664d9de3f4ac", - "dropbox_url": "https://www.dropbox.com/s/283elifjihv6289/udistrict.bin.zip?dl=0" + "checksum": "c23ccee90f71ae28e0598f9397c7261f", + "dropbox_url": "https://www.dropbox.com/s/zlx8wq2h10pgkaa/udistrict.bin.zip?dl=0" }, "data/system/maps/west_seattle.bin": { - "checksum": "e867cc142ecf22d2dbd888a1cb76fd41", - "dropbox_url": "https://www.dropbox.com/s/ftqt1adtkd0vhdy/west_seattle.bin.zip?dl=0" + "checksum": "59c42bf75491ef4613762e1305d6d487", + "dropbox_url": "https://www.dropbox.com/s/5mdf06v9kajj4mv/west_seattle.bin.zip?dl=0" }, "data/system/maps/xian.bin": { - "checksum": "35b50a1a8d33101c55947e4d5ee8985d", - "dropbox_url": "https://www.dropbox.com/s/ydl6tfzt2k60to5/xian.bin.zip?dl=0" + "checksum": "20944e89d1802ea9d6074a6c7ff184cc", + "dropbox_url": "https://www.dropbox.com/s/7bx35jcq5oz2aix/xian.bin.zip?dl=0" }, "data/system/prebaked_results/lakeslice/weekday.bin": { "checksum": "c6e5e318341ef37ae6139bb0d5596e53", diff --git a/game/src/devtools/osm_viewer.rs b/game/src/devtools/osm_viewer.rs index 7f6064079a..d1168d77b1 100644 --- a/game/src/devtools/osm_viewer.rs +++ b/game/src/devtools/osm_viewer.rs @@ -161,6 +161,22 @@ impl Viewer { } } col.push(txt.draw(ctx)); + + if !b.osm_tags.is_empty() { + for (k, v) in b.osm_tags.inner() { + if k.starts_with("abst:") { + continue; + } + col.push(Widget::row(vec![ + Btn::plaintext(k).build( + ctx, + format!("open https://wiki.openstreetmap.org/wiki/Key:{}", k), + None, + ), + Line(v).draw(ctx).align_right(), + ])); + } + } } Some(ID::ParkingLot(pl)) => { let pl = app.primary.map.get_pl(pl); diff --git a/game/src/info/building.rs b/game/src/info/building.rs index d0712ec5ce..a68e83f0b0 100644 --- a/game/src/info/building.rs +++ b/game/src/info/building.rs @@ -105,6 +105,18 @@ pub fn info(ctx: &mut EventCtx, app: &App, details: &mut Details, id: BuildingID if app.opts.dev { rows.push(Btn::text_bg1("Open OSM").build(ctx, format!("open {}", b.orig_id), None)); + + if !b.osm_tags.is_empty() { + rows.push("Raw OpenStreetMap data".draw_text(ctx)); + rows.extend(make_table( + ctx, + b.osm_tags + .inner() + .iter() + .map(|(k, v)| (k, v.to_string())) + .collect(), + )); + } } rows diff --git a/importer/src/main.rs b/importer/src/main.rs index a701c563a0..20ff18bbba 100644 --- a/importer/src/main.rs +++ b/importer/src/main.rs @@ -23,6 +23,7 @@ struct Job { scenario_everyone: bool, skip_ch: bool, + keep_bldg_tags: bool, only_map: Option, @@ -46,6 +47,8 @@ fn main() { // Skip the most expensive step of --map, building contraction hierarchies. The simulation // will use a slower method to pathfind. skip_ch: args.enabled("--skip_ch"), + // Preserve OSM tags for buildings, increasing the file size. + keep_bldg_tags: args.enabled("--keep_bldg_tags"), // Only process one map. If not specified, process all maps defined by clipping polygons in // data/input/$city/polygons/. @@ -87,6 +90,7 @@ fn main() { job.oneshot_clip, !job.oneshot_drive_on_left, !job.skip_ch, + job.keep_bldg_tags, ); return; } @@ -137,7 +141,7 @@ fn main() { } let mut maybe_map = if job.raw_to_map { - let mut map = utils::raw_to_map(&name, !job.skip_ch, &mut timer); + let mut map = utils::raw_to_map(&name, !job.skip_ch, job.keep_bldg_tags, &mut timer); // Another strange step in the pipeline. if name == "berlin_center" { @@ -197,7 +201,13 @@ fn main() { } } -fn oneshot(osm_path: String, clip: Option, drive_on_right: bool, build_ch: bool) { +fn oneshot( + osm_path: String, + clip: Option, + drive_on_right: bool, + build_ch: bool, + keep_bldg_tags: bool, +) { let mut timer = abstutil::Timer::new("oneshot"); println!("- Running convert_osm on {}", osm_path); let name = abstutil::basename(&osm_path); @@ -227,7 +237,7 @@ fn oneshot(osm_path: String, clip: Option, drive_on_right: bool, build_c ); // Often helpful to save intermediate representation in case user wants to load into map_editor raw.save(); - let map = map_model::Map::create_from_raw(raw, build_ch, &mut timer); + let map = map_model::Map::create_from_raw(raw, build_ch, keep_bldg_tags, &mut timer); timer.start("save map"); map.save(); timer.stop("save map"); diff --git a/importer/src/seattle.rs b/importer/src/seattle.rs index 608caa9215..162e5d7992 100644 --- a/importer/src/seattle.rs +++ b/importer/src/seattle.rs @@ -128,7 +128,7 @@ pub fn ensure_popdat_exists( let huge_map = if abstutil::file_exists(abstutil::path_map("huge_seattle")) { map_model::Map::new(abstutil::path_map("huge_seattle"), timer) } else { - crate::utils::raw_to_map("huge_seattle", true, timer) + crate::utils::raw_to_map("huge_seattle", true, false, timer) }; (crate::soundcast::import_data(&huge_map, timer), huge_map) diff --git a/importer/src/utils.rs b/importer/src/utils.rs index 5b8e57dc27..38e41cb86b 100644 --- a/importer/src/utils.rs +++ b/importer/src/utils.rs @@ -132,10 +132,15 @@ fn run(cmd: &mut Command) { } // Converts a RawMap to a Map. -pub fn raw_to_map(name: &str, build_ch: bool, timer: &mut Timer) -> map_model::Map { +pub fn raw_to_map( + name: &str, + build_ch: bool, + keep_bldg_tags: bool, + timer: &mut Timer, +) -> map_model::Map { timer.start(format!("Raw->Map for {}", name)); let raw: map_model::raw::RawMap = abstutil::read_binary(abstutil::path_raw_map(name), timer); - let map = map_model::Map::create_from_raw(raw, build_ch, timer); + let map = map_model::Map::create_from_raw(raw, build_ch, keep_bldg_tags, timer); timer.start("save map"); map.save(); timer.stop("save map"); diff --git a/map_model/src/make/buildings.rs b/map_model/src/make/buildings.rs index 5ef5c74b74..7dd85c51ce 100644 --- a/map_model/src/make/buildings.rs +++ b/map_model/src/make/buildings.rs @@ -16,6 +16,7 @@ use crate::{ pub fn make_all_buildings( input: &BTreeMap, map: &Map, + keep_bldg_tags: bool, timer: &mut Timer, ) -> Vec { timer.start("convert buildings"); @@ -94,6 +95,11 @@ pub fn make_all_buildings( b.osm_tags.is("building", "parking") || b.osm_tags.is("amenity", "parking"), ) }, + osm_tags: if keep_bldg_tags { + b.osm_tags.clone() + } else { + Tags::new(BTreeMap::new()) + }, sidewalk_pos: *sidewalk_pos, driveway_geom: sidewalk_line.to_polyline(), diff --git a/map_model/src/make/mod.rs b/map_model/src/make/mod.rs index 30290db0e4..d47d0a57c6 100644 --- a/map_model/src/make/mod.rs +++ b/map_model/src/make/mod.rs @@ -25,7 +25,12 @@ pub mod turns; mod walking_turns; impl Map { - pub fn create_from_raw(mut raw: RawMap, build_ch: bool, timer: &mut Timer) -> Map { + pub fn create_from_raw( + mut raw: RawMap, + build_ch: bool, + keep_bldg_tags: bool, + timer: &mut Timer, + ) -> Map { // Better to defer this and see RawMaps with more debug info in map_editor remove_disconnected::remove_disconnected_roads(&mut raw, timer); @@ -199,7 +204,8 @@ impl Map { .map(|x| x.ends_with("_link")) .unwrap_or(false) || road.osm_tags.is_any("railway", vec!["rail", "light_rail"]) - || road.osm_tags.is("junction", "roundabout")) + || road.osm_tags.is("junction", "roundabout") + || road.osm_tags.is("highway", "service")) { timer.warn(format!( "{} has no name. Tags: {:?}", @@ -267,7 +273,7 @@ impl Map { } timer.stop("find blackholes"); - map.buildings = buildings::make_all_buildings(&raw.buildings, &map, timer); + map.buildings = buildings::make_all_buildings(&raw.buildings, &map, keep_bldg_tags, timer); map.parking_lots = parking_lots::make_all_parking_lots( &raw.parking_lots, diff --git a/map_model/src/map.rs b/map_model/src/map.rs index 7ea26b96db..4fcdbcf4c2 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -101,7 +101,7 @@ impl Map { } let raw: RawMap = abstutil::read_binary(path, timer); - Map::create_from_raw(raw, true, timer) + Map::create_from_raw(raw, true, false, timer) } /// If you have to deserialize a `Map` directly, call this after. Prefer using `Map::new` diff --git a/map_model/src/objects/building.rs b/map_model/src/objects/building.rs index 8cf645f7f3..8de8f22cde 100644 --- a/map_model/src/objects/building.rs +++ b/map_model/src/objects/building.rs @@ -43,6 +43,8 @@ pub struct Building { pub amenities: BTreeSet<(NamePerLanguage, String)>, pub bldg_type: BuildingType, pub parking: OffstreetParking, + /// Depending on options while importing, these might be empty, to save file space. + pub osm_tags: Tags, /// The building's connection for pedestrians is immutable. For cars and bikes, it can change /// based on map edits, so don't cache it. diff --git a/map_tests/src/main.rs b/map_tests/src/main.rs index d7305fb8c3..4912b459c0 100644 --- a/map_tests/src/main.rs +++ b/map_tests/src/main.rs @@ -42,7 +42,7 @@ fn import_map(path: String) -> Map { }, &mut timer, ); - let map = Map::create_from_raw(raw, true, &mut timer); + let map = Map::create_from_raw(raw, true, true, &mut timer); map }