mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 09:25:15 +03:00
Make a tool to dump the map in JSON.
This commit is contained in:
parent
8f258b33a6
commit
7cbc0fd95c
22
Cargo.lock
generated
22
Cargo.lock
generated
@ -1532,6 +1532,17 @@ dependencies = [
|
||||
"stdweb 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iotool"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abstutil 0.1.0",
|
||||
"geom 0.1.0",
|
||||
"map_model 0.1.0",
|
||||
"serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sim 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iovec"
|
||||
version = "0.1.4"
|
||||
@ -3342,17 +3353,6 @@ dependencies = [
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "traffic_importer"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abstutil 0.1.0",
|
||||
"geom 0.1.0",
|
||||
"map_model 0.1.0",
|
||||
"serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sim 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "try-lock"
|
||||
version = "0.2.2"
|
||||
|
@ -8,11 +8,11 @@ members = [
|
||||
"geom",
|
||||
"headless",
|
||||
"importer",
|
||||
"iotool",
|
||||
"kml",
|
||||
"map_editor",
|
||||
"map_model",
|
||||
"sim",
|
||||
"traffic_importer",
|
||||
"updater",
|
||||
]
|
||||
|
||||
|
@ -37,3 +37,19 @@ are missing, etc. A summary of the commands available so far:
|
||||
mode, duration of trip in seconds). The mode is either a string like "Walk"
|
||||
or "Drive", or null if the trip was aborted (due to a simulation bug or
|
||||
disconnected map).
|
||||
|
||||
## Related tools
|
||||
|
||||
There's no API to create trips. Instead, you can
|
||||
[import trips from your own data](https://dabreegster.github.io/abstreet/trafficsim/travel_demand.html#custom-import).
|
||||
|
||||
If you need to deeply inspect the map, you can dump it to JSON:
|
||||
|
||||
```
|
||||
cargo run --bin iotool -- dump_map --map=data/system/maps/montlake.bin
|
||||
```
|
||||
|
||||
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](https://dabreegster.github.io/abstreet/map/index.html)
|
||||
in the meantime.
|
||||
|
@ -23,6 +23,7 @@ One-time setup:
|
||||
|
||||
## Development tips
|
||||
|
||||
- [Generated API documentation](https://dabreegster.github.io/abstreet/rustdoc/map_model/index.html)
|
||||
- Compile faster by just doing `cargo run`. The executable will have debug stack
|
||||
traces and run more slowly. You can do `cargo run --release` to build in
|
||||
optimized release mode; compilation will be slower, but the executable much
|
||||
@ -136,6 +137,7 @@ Common utilities:
|
||||
- `abstutil`: a grab-bag of IO helpers, timing and logging utilities, etc
|
||||
- `geom`: types for GPS and map-space points, lines, angles, polylines,
|
||||
polygons, circles, durations, speeds
|
||||
- `iotool`: a catch-all tool to import/export data
|
||||
|
||||
## Code conventions
|
||||
|
||||
|
@ -92,7 +92,7 @@ example:
|
||||
Run the tool:
|
||||
|
||||
```
|
||||
cargo run --bin traffic_importer -- --map=data/system/maps/montlake.bin --input=/path/to/input.json
|
||||
cargo run --bin iotool -- import_traffic --map=data/system/maps/montlake.bin --input=/path/to/input.json
|
||||
```
|
||||
|
||||
The tool matches input positions to the nearest building or border intersection,
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "traffic_importer"
|
||||
name = "iotool"
|
||||
version = "0.1.0"
|
||||
authors = ["Dustin Carlino <dabreegster@gmail.com>"]
|
||||
edition = "2018"
|
@ -6,10 +6,21 @@ use sim::{IndividTrip, PersonID, PersonSpec, Scenario, SpawnTrip, TripEndpoint,
|
||||
|
||||
fn main() {
|
||||
let mut args = CmdArgs::new();
|
||||
let map = args.required("--map");
|
||||
let input = args.required("--input");
|
||||
args.done();
|
||||
match args.required_free().as_ref() {
|
||||
"import_traffic" => {
|
||||
import_traffic(args.required("--map"), args.required("--input"));
|
||||
args.done();
|
||||
}
|
||||
"dump_map" => {
|
||||
let map = Map::new(args.required("--map"), &mut Timer::new("dump map"));
|
||||
println!("{}", abstutil::to_json(&map));
|
||||
args.done();
|
||||
}
|
||||
x => panic!("Unknown command {}. Try: import_traffic, dump_map", x),
|
||||
}
|
||||
}
|
||||
|
||||
fn import_traffic(map: String, input: String) {
|
||||
let mut timer = Timer::new("import traffic demand data");
|
||||
let map = Map::new(map, &mut timer);
|
||||
let input: Input = abstutil::read_json(input, &mut timer);
|
Loading…
Reference in New Issue
Block a user