parse gtfs during map conversion

This commit is contained in:
Dustin Carlino 2018-09-07 11:46:30 -07:00
parent 9c317137d7
commit 143084a8a9
11 changed files with 27 additions and 22 deletions

View File

@ -10,6 +10,7 @@ byteorder = "1.2.1"
dimensioned = { git = "https://github.com/paholg/dimensioned", rev = "0e1076ebfa5128d1ee544bdc9754c948987b6fe3", features = ["serde"] }
geo = "0.9.1"
geom = { path = "../geom" }
gtfs = { path = "../gtfs" }
ordered-float = "0.5.0"
osm-xml = "0.5.1"
map_model = { path = "../map_model" }

View File

@ -4,6 +4,7 @@ extern crate byteorder;
extern crate dimensioned;
extern crate geo;
extern crate geom;
extern crate gtfs;
extern crate map_model;
extern crate ordered_float;
extern crate osm_xml;
@ -44,6 +45,10 @@ pub struct Flags {
#[structopt(long = "parcels")]
pub parcels: String,
/// GTFS directory
#[structopt(long = "gtfs")]
pub gtfs: String,
/// Output .abst path
#[structopt(long = "output")]
pub output: String,
@ -98,5 +103,7 @@ pub fn convert(flags: &Flags) -> raw_data::Map {
}
}
map.bus_routes = gtfs::load(&flags.gtfs).unwrap();
map
}

View File

@ -8,3 +8,5 @@ csv = "1.0.1"
failure = "0.1.2"
geom = { path = "../geom" }
itertools = "0.7.8"
serde = "1.0"
serde_derive = "1.0"

View File

@ -2,6 +2,9 @@ extern crate csv;
extern crate failure;
extern crate geom;
extern crate itertools;
extern crate serde;
#[macro_use]
extern crate serde_derive;
use failure::Error;
use geom::LonLat;
@ -10,7 +13,7 @@ use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::time::Instant;
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Route {
pub name: String,
pub stops: Vec<LonLat>,

View File

@ -16,6 +16,7 @@ mkdir -p data/input
ELEVATION=../data/input/N47W122.hgt
PARCELS_KML=../data/input/King_County_Parcels__parcel_area.kml
TRAFFIC_SIGNALS=../data/input/TrafficSignals.shp
GTFS=../data/input/google_transit_2018_18_08
SMALL_OSM=../data/input/tiny_montlake.osm
MEDIUM_OSM=../data/input/montlake.osm
@ -28,7 +29,7 @@ if [ ! -f data/seattle_parcels.abst ]; then
cd ..
fi
COMMON="--elevation=$ELEVATION --traffic_signals=$TRAFFIC_SIGNALS --parcels=../data/seattle_parcels.abst"
COMMON="--elevation=$ELEVATION --traffic_signals=$TRAFFIC_SIGNALS --parcels=../data/seattle_parcels.abst --gtfs=$GTFS"
cd convert_osm
time cargo run --release -- --osm=$SMALL_OSM $COMMON --output=../data/small.abst
time cargo run --release -- --osm=$MEDIUM_OSM $COMMON --output=../data/medium.abst

View File

@ -10,11 +10,11 @@ use {BusStop, BusStopDetails, Lane, LaneID, Road};
pub fn make_bus_stops(
lanes: &mut Vec<Lane>,
roads: &Vec<Road>,
bus_routes: Vec<gtfs::Route>,
bus_routes: &Vec<gtfs::Route>,
bounds: &Bounds,
) {
let mut bus_stop_pts: HashSet<HashablePt2D> = HashSet::new();
for route in &bus_routes {
for route in bus_routes {
for gps in &route.stops {
if bounds.contains(gps.longitude, gps.latitude) {
bus_stop_pts.insert(Pt2D::from_gps(&gps, bounds).into());

View File

@ -5,7 +5,6 @@ use building::{Building, BuildingID};
use edits::Edits;
use geom::{Bounds, HashablePt2D, PolyLine, Pt2D};
use geometry;
use gtfs;
use intersection::{Intersection, IntersectionID};
use lane::{BusStop, BusStopDetails, Lane, LaneID, LaneType};
use make;
@ -33,7 +32,7 @@ pub struct Map {
}
impl Map {
pub fn new(path: &str, edits: &Edits, bus_routes: Vec<gtfs::Route>) -> Result<Map, Error> {
pub fn new(path: &str, edits: &Edits) -> Result<Map, Error> {
let data: raw_data::Map = abstutil::read_binary(path)?;
Ok(Map::create_from_raw(
path::Path::new(path)
@ -44,16 +43,10 @@ impl Map {
.unwrap(),
data,
edits,
bus_routes,
))
}
pub fn create_from_raw(
name: String,
data: raw_data::Map,
edits: &Edits,
bus_routes: Vec<gtfs::Route>,
) -> Map {
pub fn create_from_raw(name: String, data: raw_data::Map, edits: &Edits) -> Map {
let bounds = data.get_gps_bounds();
let mut m = Map {
name,
@ -159,7 +152,7 @@ impl Map {
}
}
make::make_bus_stops(&mut m.lanes, &m.roads, bus_routes, &bounds);
make::make_bus_stops(&mut m.lanes, &m.roads, &data.bus_routes, &bounds);
for i in &m.intersections {
for t in make::make_all_turns(i, &m) {

View File

@ -1,5 +1,6 @@
use dimensioned::si;
use geom::{Bounds, HashablePt2D, LonLat};
use gtfs::Route;
use std::collections::BTreeMap;
#[derive(PartialEq, Debug, Serialize, Deserialize)]
@ -8,6 +9,7 @@ pub struct Map {
pub intersections: Vec<Intersection>,
pub buildings: Vec<Building>,
pub parcels: Vec<Parcel>,
pub bus_routes: Vec<Route>,
pub coordinates_in_world_space: bool,
}
@ -19,6 +21,7 @@ impl Map {
intersections: Vec::new(),
buildings: Vec::new(),
parcels: Vec::new(),
bus_routes: Vec::new(),
coordinates_in_world_space: false,
}
}

View File

@ -12,7 +12,6 @@ dimensioned = { git = "https://github.com/paholg/dimensioned", rev = "0e1076ebfa
ezgui = { path = "../ezgui" }
failure = "0.1.2"
geom = { path = "../geom" }
gtfs = { path = "../gtfs" }
lazy_static = "1.1.0"
map_model = { path = "../map_model" }
more-asserts = "0.2.1"

View File

@ -1,6 +1,5 @@
use abstutil;
use control::ControlMap;
use gtfs;
use map_model::{BuildingID, BusStop, Edits, LaneID, Map};
use rand::Rng;
use std::collections::VecDeque;
@ -13,22 +12,20 @@ pub fn load(
rng_seed: Option<u8>,
savestate_every: Option<Tick>,
) -> (Map, Edits, ControlMap, Sim) {
// Hardcoded files for road edits and transit data.
let edits: Edits = abstutil::read_json("road_edits.json").unwrap_or(Edits::new());
let bus_routes = gtfs::load("../data/input/google_transit_2018_18_08").unwrap();
if input.contains("data/save/") {
println!("Resuming from {}", input);
let sim: Sim = abstutil::read_json(&input).expect("loading sim state failed");
// TODO assuming the relative path :(
let map_path = format!("../data/{}.abst", sim.map_name);
let map = Map::new(&map_path, &edits, bus_routes)
.expect(&format!("Couldn't load map from {}", map_path));
let map =
Map::new(&map_path, &edits).expect(&format!("Couldn't load map from {}", map_path));
let control_map = ControlMap::new(&map);
(map, edits, control_map, sim)
} else {
println!("Loading map {}", input);
let map = Map::new(&input, &edits, bus_routes).expect("Couldn't load map");
let map = Map::new(&input, &edits).expect("Couldn't load map");
let control_map = ControlMap::new(&map);
let sim = Sim::new(&map, scenario_name, rng_seed, savestate_every);
(map, edits, control_map, sim)

View File

@ -11,7 +11,6 @@ extern crate ezgui;
extern crate failure;
extern crate geom;
extern crate graphics;
extern crate gtfs;
#[macro_use]
extern crate lazy_static;
extern crate map_model;