From 6a2c391b8b717ef828b4efafe7d1645a6f7c0a9d Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 18 Nov 2020 11:34:38 -0800 Subject: [PATCH] Add a tool to convert maps from JSON back to binary, to enable experiments with modifying parking per buildings. Except... apparently we can't read back in JSON maps?! --- book/src/dev/api.md | 14 ++++++++++++++ importer/src/bin/json_to_binary_map.rs | 11 +++++++++++ 2 files changed, 25 insertions(+) create mode 100644 importer/src/bin/json_to_binary_map.rs diff --git a/book/src/dev/api.md b/book/src/dev/api.md index 13fe990ec9..5ef74ac7fb 100644 --- a/book/src/dev/api.md +++ b/book/src/dev/api.md @@ -108,6 +108,20 @@ cargo run --bin dump_map data/system/seattle/maps/montlake.bin > montlake.json See some example code that [reads this JSON and finds buildings](https://github.com/dabreegster/abstreet/blob/master/headless/examples/generate_traffic.py). +You could also edit the map JSON, convert it back to binary, and use it in the +simulation. This isn't recommended generally, but one possible use case could be +tuning the amount of offstreet parking per building. The map JSON has a list +called `buildings`, and each object there has a field `parking`. You coud set +this object to `{ "Private": [100, false] }` to indicate 100 parking spots, for +a building not explicitly designated in OpenStreetMap as a garage. After editing +the JSON, you have to convert it back to the binary format: + +``` +cargo run --bin json_to_binary_map -- --input=montlake.json out=data/system/seattle/maps/montlake_modified.bin` +``` + +... Except this tool doesn't seem to work yet! + The format of the map isn't well-documented yet. See the [generated API docs](https://dabreegster.github.io/abstreet/rustdoc/map_model/index.html) and [the map model docs](../map/index.md) in the meantime. diff --git a/importer/src/bin/json_to_binary_map.rs b/importer/src/bin/json_to_binary_map.rs new file mode 100644 index 0000000000..0238ee84f1 --- /dev/null +++ b/importer/src/bin/json_to_binary_map.rs @@ -0,0 +1,11 @@ +use abstutil::{CmdArgs, Timer}; +use map_model::Map; + +fn main() { + let mut args = CmdArgs::new(); + // TODO This can't handle the output of dump_map! What?! + let mut map: Map = abstutil::read_json(args.required("--input"), &mut Timer::throwaway()); + map.map_loaded_directly(); + abstutil::write_binary(args.required("--output"), &map); + args.done(); +}