Move iotool things into the importer package, but keep separate binaries

This commit is contained in:
Dustin Carlino 2020-09-03 11:49:53 -07:00
parent db23cf2d57
commit b13f5b0f4a
9 changed files with 19 additions and 51 deletions

11
Cargo.lock generated
View File

@ -1492,17 +1492,6 @@ 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"

View File

@ -7,7 +7,6 @@ members = [
"geom",
"headless",
"importer",
"iotool",
"kml",
"map_editor",
"map_model",

View File

@ -137,7 +137,6 @@ 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

View File

@ -59,7 +59,7 @@ There's no API to create trips. Instead, you can
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
cargo run --bin dump_map data/system/maps/montlake.bin
```
The format of the map isn't well-documented yet. See the

View File

@ -92,7 +92,7 @@ example:
Run the tool:
```
cargo run --bin iotool -- import_traffic --map=data/system/maps/montlake.bin --input=/path/to/input.json
cargo run --bin 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,

View File

@ -0,0 +1,9 @@
use abstutil::{CmdArgs, Timer};
use map_model::Map;
fn main() {
let mut args = CmdArgs::new();
let map = Map::new(args.required_free(), &mut Timer::throwaway());
println!("{}", abstutil::to_json(&map));
args.done();
}

View File

@ -1,5 +1,5 @@
use std::io::{self, Read};
use geojson::{GeoJson, Value};
use std::io::{self, Read};
/// Convert geojson boundary suitable for osmfilter and other osmosis based tools.
/// Expects the input to contain no element other than the boundary of interest.
@ -26,17 +26,12 @@ fn boundary_coords(geojson: &GeoJson) -> Result<Vec<Vec<f64>>, Box<dyn std::erro
let feature = match geojson {
GeoJson::Feature(feature) => feature,
GeoJson::FeatureCollection(feature_collection) => &feature_collection.features[0],
_ => return Err(format!("Unexpected geojson: {:?}", geojson).into())
_ => return Err(format!("Unexpected geojson: {:?}", geojson).into()),
};
match &feature.geometry.as_ref().map(|g| &g.value) {
Some(Value::MultiPolygon(multi_polygon)) => {
return Ok(multi_polygon[0][0].clone())
},
Some(Value::Polygon(polygon)) => {
return Ok(polygon[0].clone())
},
_ => Err(format!("Unexpected feature: {:?}", feature).into())
Some(Value::MultiPolygon(multi_polygon)) => return Ok(multi_polygon[0][0].clone()),
Some(Value::Polygon(polygon)) => return Ok(polygon[0].clone()),
_ => Err(format!("Unexpected feature: {:?}", feature).into()),
}
}

View File

@ -6,21 +6,10 @@ use sim::{IndividTrip, PersonID, PersonSpec, Scenario, SpawnTrip, TripEndpoint,
fn main() {
let mut args = CmdArgs::new();
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),
}
}
let map = args.required("--map");
let input = args.required("--input");
args.done();
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);

View File

@ -1,12 +0,0 @@
[package]
name = "iotool"
version = "0.1.0"
authors = ["Dustin Carlino <dabreegster@gmail.com>"]
edition = "2018"
[dependencies]
abstutil = { path = "../abstutil" }
geom = { path = "../geom" }
map_model = { path = "../map_model" }
serde = "1.0.110"
sim = { path = "../sim" }