Skip to content

Commit

Permalink
Optionally dump the extracted GTFS data as a shapefile to visually de…
Browse files Browse the repository at this point in the history
…bug. #372
  • Loading branch information
dabreegster committed Dec 3, 2021
1 parent 726ad11 commit 5482070
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions convert_osm/src/gtfs.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fs::File;

use anyhow::Result;
use serde::Deserialize;

use abstutil::MultiMap;
use geom::{LonLat, PolyLine, Pt2D};
use kml::{ExtraShape, ExtraShapes};
use map_model::raw::{RawMap, RawTransitRoute, RawTransitStop};
use map_model::PathConstraints;

Expand All @@ -24,7 +25,11 @@ pub fn import(map: &mut RawMap) -> Result<()> {
_ => continue,
};
map.transit_routes.push(RawTransitRoute {
long_name: rec.route_long_name,
long_name: if rec.route_long_name.is_empty() {
rec.route_desc
} else {
rec.route_long_name
},
short_name: rec.route_short_name,
gtfs_id: rec.route_id.0,
shape: PolyLine::dummy(),
Expand Down Expand Up @@ -164,6 +169,10 @@ pub fn import(map: &mut RawMap) -> Result<()> {
map.transit_stops
.retain(|stop_id, _| used_stops.contains(stop_id));

if true {
dump_kml(map);
}

Ok(())
}

Expand All @@ -181,6 +190,7 @@ struct Route {
route_id: RouteID,
route_short_name: String,
route_long_name: String,
route_desc: String,
route_type: usize,
}

Expand Down Expand Up @@ -213,3 +223,35 @@ struct StopTime {
stop_id: StopID,
stop_sequence: usize,
}

fn dump_kml(map: &RawMap) {
let mut shapes = Vec::new();

// One polyline per route
for route in &map.transit_routes {
let points = map.gps_bounds.convert_back(route.shape.points());
let mut attributes = BTreeMap::new();
attributes.insert("long_name".to_string(), route.long_name.clone());
attributes.insert("short_name".to_string(), route.short_name.clone());
attributes.insert("gtfs_id".to_string(), route.gtfs_id.clone());
attributes.insert("num_stops".to_string(), route.stops.len().to_string());
attributes.insert("route_type".to_string(), format!("{:?}", route.route_type));
shapes.push(ExtraShape { points, attributes });
}

// One point per stop
for stop in map.transit_stops.values() {
let mut attributes = BTreeMap::new();
attributes.insert("gtfs_id".to_string(), stop.gtfs_id.clone());
attributes.insert("name".to_string(), stop.name.clone());
let points = vec![stop.position.to_gps(&map.gps_bounds)];
shapes.push(ExtraShape { points, attributes });
}

abstio::write_binary(
map.name
.city
.input_path(format!("gtfs_{}.bin", map.name.map)),
&ExtraShapes { shapes },
);
}

0 comments on commit 5482070

Please sign in to comment.