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?!

This commit is contained in:
Dustin Carlino 2020-11-18 11:34:38 -08:00
parent 4ab98b1477
commit 6a2c391b8b
2 changed files with 25 additions and 0 deletions

View File

@ -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.

View File

@ -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();
}