rename raw_data layer of stuff for easier importing, disambiguation

This commit is contained in:
Dustin Carlino 2019-09-23 15:00:55 -07:00
parent 333f976721
commit 536df84844
19 changed files with 130 additions and 129 deletions

View File

@ -1,8 +1,9 @@
use abstutil::{retain_btreemap, Timer};
use geom::PolyLine;
use map_model::{raw_data, IntersectionType};
use map_model::raw::{RawMap, StableIntersectionID, StableRoadID};
use map_model::IntersectionType;
pub fn clip_map(map: &mut raw_data::Map, timer: &mut Timer) {
pub fn clip_map(map: &mut RawMap, timer: &mut Timer) {
timer.start("clipping map to boundary");
// So we can use retain_btreemap without borrowing issues
@ -22,7 +23,7 @@ pub fn clip_map(map: &mut raw_data::Map, timer: &mut Timer) {
first_in || last_in
});
let road_ids: Vec<raw_data::StableRoadID> = map.roads.keys().cloned().collect();
let road_ids: Vec<StableRoadID> = map.roads.keys().cloned().collect();
for id in road_ids {
let r = &map.roads[&id];
let first_in = map.boundary_polygon.contains_pt(r.center_points[0]);
@ -52,7 +53,7 @@ pub fn clip_map(map: &mut raw_data::Map, timer: &mut Timer) {
copy.orig_id.osm_node_id = map.new_osm_node_id();
// Nothing deletes intersections yet, so this is safe.
move_i = raw_data::StableIntersectionID(map.intersections.len());
move_i = StableIntersectionID(map.intersections.len());
map.intersections.insert(move_i, copy);
println!("Disconnecting {} from some other stuff", id);
// We don't need to mark the existing intersection as a border and make sure to split

View File

@ -6,7 +6,8 @@ mod split_ways;
use abstutil::{prettyprint_usize, Timer};
use geom::{Distance, FindClosest, Line, PolyLine, Pt2D};
use kml::ExtraShapes;
use map_model::{osm, raw_data, LaneID, OffstreetParking, Position, LANE_THICKNESS};
use map_model::raw::{RawMap, StableBuildingID, StableRoadID};
use map_model::{osm, LaneID, OffstreetParking, Position, LANE_THICKNESS};
use std::collections::BTreeMap;
pub struct Flags {
@ -20,7 +21,7 @@ pub struct Flags {
pub output: String,
}
pub fn convert(flags: &Flags, timer: &mut abstutil::Timer) -> raw_data::Map {
pub fn convert(flags: &Flags, timer: &mut abstutil::Timer) -> RawMap {
let mut map = split_ways::split_up_roads(
osm_reader::extract_osm(&flags.osm, &flags.clip, timer),
timer,
@ -56,7 +57,7 @@ pub fn convert(flags: &Flags, timer: &mut abstutil::Timer) -> raw_data::Map {
map
}
fn check_orig_ids(map: &raw_data::Map) {
fn check_orig_ids(map: &RawMap) {
{
let mut ids = BTreeMap::new();
for (id, r) in &map.roads {
@ -86,12 +87,12 @@ fn check_orig_ids(map: &raw_data::Map) {
}
}
fn use_parking_hints(map: &mut raw_data::Map, path: &str, timer: &mut Timer) {
fn use_parking_hints(map: &mut RawMap, path: &str, timer: &mut Timer) {
timer.start("apply parking hints");
let shapes: ExtraShapes = abstutil::read_binary(path, timer).expect("loading blockface failed");
// Match shapes with the nearest road + direction (true for forwards)
let mut closest: FindClosest<(raw_data::StableRoadID, bool)> =
let mut closest: FindClosest<(StableRoadID, bool)> =
FindClosest::new(&map.gps_bounds.to_bounds());
for (id, r) in &map.roads {
let center = PolyLine::new(r.center_points.clone());
@ -144,13 +145,13 @@ fn use_parking_hints(map: &mut raw_data::Map, path: &str, timer: &mut Timer) {
timer.stop("apply parking hints");
}
fn use_street_signs(map: &mut raw_data::Map, path: &str, timer: &mut Timer) {
fn use_street_signs(map: &mut RawMap, path: &str, timer: &mut Timer) {
timer.start("apply street signs to override parking hints");
let shapes: ExtraShapes =
abstutil::read_binary(path, timer).expect("loading street_signs failed");
// Match shapes with the nearest road + direction (true for forwards)
let mut closest: FindClosest<(raw_data::StableRoadID, bool)> =
let mut closest: FindClosest<(StableRoadID, bool)> =
FindClosest::new(&map.gps_bounds.to_bounds());
for (id, r) in &map.roads {
let center = PolyLine::new(r.center_points.clone());
@ -194,12 +195,11 @@ fn use_street_signs(map: &mut raw_data::Map, path: &str, timer: &mut Timer) {
timer.stop("apply street signs to override parking hints");
}
fn use_offstreet_parking(map: &mut raw_data::Map, path: &str, timer: &mut Timer) {
fn use_offstreet_parking(map: &mut RawMap, path: &str, timer: &mut Timer) {
timer.start("match offstreet parking points");
let shapes = kml::load(path, &map.gps_bounds, timer).expect("loading offstreet_parking failed");
let mut closest: FindClosest<raw_data::StableBuildingID> =
FindClosest::new(&map.gps_bounds.to_bounds());
let mut closest: FindClosest<StableBuildingID> = FindClosest::new(&map.gps_bounds.to_bounds());
for (id, b) in &map.buildings {
closest.add(*id, b.polygon.points());
}

View File

@ -1,6 +1,9 @@
use abstutil::{FileWithProgress, Timer};
use geom::{GPSBounds, HashablePt2D, LonLat, Polygon, Pt2D};
use map_model::{osm, raw_data, AreaType};
use map_model::raw::{
OriginalRoad, RawArea, RawBuilding, RawMap, RawRoad, StableBuildingID, StableIntersectionID,
};
use map_model::{osm, AreaType};
use osm_xml;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fs::File;
@ -11,9 +14,9 @@ pub fn extract_osm(
maybe_clip_path: &Option<String>,
timer: &mut Timer,
) -> (
raw_data::Map,
RawMap,
// Un-split roads
Vec<raw_data::Road>,
Vec<RawRoad>,
// Traffic signals
HashSet<HashablePt2D>,
// OSM Node IDs
@ -32,7 +35,7 @@ pub fn extract_osm(
let mut map = if let Some(ref path) = maybe_clip_path {
read_osmosis_polygon(path)
} else {
let mut m = raw_data::Map::blank(abstutil::basename(osm_path));
let mut m = RawMap::blank(abstutil::basename(osm_path));
for node in doc.nodes.values() {
m.gps_bounds.update(LonLat::new(node.lon, node.lat));
}
@ -41,7 +44,7 @@ pub fn extract_osm(
};
let mut id_to_way: HashMap<i64, Vec<Pt2D>> = HashMap::new();
let mut roads: Vec<raw_data::Road> = Vec::new();
let mut roads: Vec<RawRoad> = Vec::new();
let mut traffic_signals: HashSet<HashablePt2D> = HashSet::new();
let mut osm_node_ids = HashMap::new();
@ -82,8 +85,8 @@ pub fn extract_osm(
let mut tags = tags_to_map(&way.tags);
tags.insert(osm::OSM_WAY_ID.to_string(), way.id.to_string());
if is_road(&tags) {
roads.push(raw_data::Road {
orig_id: raw_data::OriginalRoad {
roads.push(RawRoad {
orig_id: OriginalRoad {
osm_way_id: way.id,
node1: osm_node_ids[&pts[0].to_hashable()],
node2: osm_node_ids[&pts.last().unwrap().to_hashable()],
@ -91,18 +94,18 @@ pub fn extract_osm(
center_points: pts,
osm_tags: tags,
// We'll fill this out later
i1: raw_data::StableIntersectionID(0),
i2: raw_data::StableIntersectionID(0),
i1: StableIntersectionID(0),
i2: StableIntersectionID(0),
});
} else if is_bldg(&tags) {
let deduped = Pt2D::approx_dedupe(pts, geom::EPSILON_DIST);
if deduped.len() < 3 {
continue;
}
let id = raw_data::StableBuildingID(map.buildings.len());
let id = StableBuildingID(map.buildings.len());
map.buildings.insert(
id,
raw_data::Building {
RawBuilding {
osm_way_id: way.id,
polygon: Polygon::new(&deduped),
osm_tags: tags,
@ -113,7 +116,7 @@ pub fn extract_osm(
if pts.len() < 3 {
continue;
}
map.areas.push(raw_data::Area {
map.areas.push(RawArea {
area_type: at,
osm_id: way.id,
polygon: Polygon::new(&pts),
@ -161,7 +164,7 @@ pub fn extract_osm(
println!("Relation {} failed to glue multipolygon", rel.id);
} else {
for polygon in polygons {
map.areas.push(raw_data::Area {
map.areas.push(RawArea {
area_type: at,
osm_id: rel.id,
polygon,
@ -327,7 +330,7 @@ fn glue_multipolygon(mut pts_per_way: Vec<Vec<Pt2D>>) -> Vec<Polygon> {
polygons
}
fn read_osmosis_polygon(path: &str) -> raw_data::Map {
fn read_osmosis_polygon(path: &str) -> RawMap {
let mut pts: Vec<LonLat> = Vec::new();
let mut gps_bounds = GPSBounds::new();
for (idx, maybe_line) in BufReader::new(File::open(path).unwrap())
@ -351,7 +354,7 @@ fn read_osmosis_polygon(path: &str) -> raw_data::Map {
gps_bounds.update(pt);
}
let mut map = raw_data::Map::blank(abstutil::basename(path));
let mut map = RawMap::blank(abstutil::basename(path));
map.boundary_polygon = Polygon::new(&gps_bounds.must_convert(&pts));
map.gps_bounds = gps_bounds;
map

View File

@ -1,23 +1,25 @@
use abstutil::{Counter, Timer};
use geom::HashablePt2D;
use map_model::{osm, raw_data, IntersectionType};
use map_model::raw::{
OriginalIntersection, RawIntersection, RawMap, RawRoad, StableIntersectionID, StableRoadID,
};
use map_model::{osm, IntersectionType};
use std::collections::{HashMap, HashSet};
pub fn split_up_roads(
(mut map, roads, traffic_signals, osm_node_ids): (
raw_data::Map,
Vec<raw_data::Road>,
RawMap,
Vec<RawRoad>,
HashSet<HashablePt2D>,
HashMap<HashablePt2D, i64>,
),
timer: &mut Timer,
) -> raw_data::Map {
) -> RawMap {
timer.start("splitting up roads");
let mut next_intersection_id = 0;
let mut pt_to_intersection: HashMap<HashablePt2D, raw_data::StableIntersectionID> =
HashMap::new();
let mut pt_to_intersection: HashMap<HashablePt2D, StableIntersectionID> = HashMap::new();
let mut counts_per_pt = Counter::new();
for r in &roads {
for (idx, raw_pt) in r.center_points.iter().enumerate() {
@ -27,7 +29,7 @@ pub fn split_up_roads(
// All start and endpoints of ways are also intersections.
if count == 2 || idx == 0 || idx == r.center_points.len() - 1 {
if !pt_to_intersection.contains_key(&pt) {
let id = raw_data::StableIntersectionID(next_intersection_id);
let id = StableIntersectionID(next_intersection_id);
next_intersection_id += 1;
pt_to_intersection.insert(pt, id);
}
@ -38,9 +40,9 @@ pub fn split_up_roads(
for (pt, id) in &pt_to_intersection {
map.intersections.insert(
*id,
raw_data::Intersection {
RawIntersection {
point: pt.to_pt2d(),
orig_id: raw_data::OriginalIntersection {
orig_id: OriginalIntersection {
osm_node_id: osm_node_ids[pt],
},
intersection_type: if traffic_signals.contains(pt) {
@ -83,8 +85,7 @@ pub fn split_up_roads(
r.orig_id.node2 = osm_node_ids[&pts.last().unwrap().to_hashable()];
r.center_points = std::mem::replace(&mut pts, Vec::new());
// Start a new road
map.roads
.insert(raw_data::StableRoadID(map.roads.len()), r.clone());
map.roads.insert(StableRoadID(map.roads.len()), r.clone());
r.osm_tags.remove(osm::ENDPT_FWD);
r.osm_tags.remove(osm::ENDPT_BACK);
r.i1 = *i2;

View File

@ -52,15 +52,15 @@ implemented this yet.
Poking around the .osm extracts in `data/input/`, you'll see a promising
relation with `route = light_rail`. The relation points to individual points
(nodes) as stops, and segments of the track (ways). These need to be represented
in the initial version of the map, `raw_data::Map`, and the final version,
`map_model::Map`. Stations probably coincide with existing buildings, and tracks
could probably be modeled as a special type of road. To remember the order of
stations and group everything, there's already a notion of bus route from the
`gtfs` crate that probably works. The `convert_osm` crate is the place to
extract this new data from OSM. It might be worth thinking about how the light
rail line gets clipped, since most maps won't include all of the stations --
should those maps just terminate trains at the stations, or should trains go to
and from the map border?
in the initial version of the map, `RawMap`, and the final version, `Map`.
Stations probably coincide with existing buildings, and tracks could probably be
modeled as a special type of road. To remember the order of stations and group
everything, there's already a notion of bus route from the `gtfs` crate that
probably works. The `convert_osm` crate is the place to extract this new data
from OSM. It might be worth thinking about how the light rail line gets clipped,
since most maps won't include all of the stations -- should those maps just
terminate trains at the stations, or should trains go to and from the map
border?
Then there are some rendering questions. How should special buildings that act
as light rail stations be displayed? What about the track between stations, and

View File

@ -3,7 +3,8 @@ use crate::helpers::ID;
use crate::ui::{PerMapUI, UI};
use ezgui::{EventCtx, EventLoopMode, GfxCtx, Warper, Wizard};
use geom::Pt2D;
use map_model::{raw_data, AreaID, BuildingID, IntersectionID, LaneID, RoadID};
use map_model::raw::{StableIntersectionID, StableRoadID};
use map_model::{AreaID, BuildingID, IntersectionID, LaneID, RoadID};
use sim::{PedestrianID, TripID};
use std::usize;
@ -109,7 +110,7 @@ fn warp_point(line: &str, primary: &PerMapUI) -> Option<(Option<ID>, Pt2D, f64)>
}
}
'I' => {
let stable_id = raw_data::StableIntersectionID(idx);
let stable_id = StableIntersectionID(idx);
if let Some(i) = primary
.map
.all_intersections()
@ -122,7 +123,7 @@ fn warp_point(line: &str, primary: &PerMapUI) -> Option<(Option<ID>, Pt2D, f64)>
}
}
'R' => {
let stable_id = raw_data::StableRoadID(idx);
let stable_id = StableRoadID(idx);
if let Some(r) = primary
.map
.all_roads()

View File

@ -3,7 +3,7 @@ use crate::render::DrawMap;
use crate::ui::PerMapUI;
use crate::ui::UI;
use ezgui::{Color, EventCtx, GfxCtx, Key, Line, Text};
use map_model::raw_data::StableRoadID;
use map_model::raw::StableRoadID;
use map_model::Map;
use sim::{CarID, Sim};
use std::collections::BTreeMap;

View File

@ -3,7 +3,7 @@ mod model;
use abstutil::CmdArgs;
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Line, Text, Wizard, GUI};
use geom::{Distance, Line, Polygon, Pt2D};
use map_model::raw_data::{StableBuildingID, StableIntersectionID, StableRoadID};
use map_model::raw::{StableBuildingID, StableIntersectionID, StableRoadID};
use model::{Direction, Model, ID};
use std::process;

View File

@ -2,11 +2,11 @@ use abstutil::{read_binary, Timer};
use ezgui::world::{Object, ObjectID, World};
use ezgui::{Color, EventCtx, GfxCtx, Line, Prerender, Text};
use geom::{Bounds, Circle, Distance, PolyLine, Polygon, Pt2D};
use map_model::raw_data::{
MapFixes, OriginalIntersection, OriginalRoad, StableBuildingID, StableIntersectionID,
StableRoadID,
use map_model::raw::{
MapFixes, OriginalIntersection, OriginalRoad, RawBuilding, RawIntersection, RawMap, RawRoad,
StableBuildingID, StableIntersectionID, StableRoadID,
};
use map_model::{osm, raw_data, IntersectionType, LaneType, RoadSpec, LANE_THICKNESS};
use map_model::{osm, IntersectionType, LaneType, RoadSpec, LANE_THICKNESS};
use std::collections::{BTreeMap, BTreeSet};
use std::mem;
@ -19,7 +19,7 @@ const FORWARDS: Direction = true;
const BACKWARDS: Direction = false;
pub struct Model {
pub map: raw_data::Map,
pub map: RawMap,
// TODO Not sure this should be pub...
pub showing_pts: Option<StableRoadID>,
@ -33,7 +33,7 @@ pub struct Model {
impl Model {
pub fn blank() -> Model {
Model {
map: raw_data::Map::blank(String::new()),
map: RawMap::blank(String::new()),
showing_pts: None,
exclude_bldgs: false,
@ -219,11 +219,11 @@ impl Model {
pub fn create_i(&mut self, point: Pt2D, prerender: &Prerender) {
let id = self
.map
.create_intersection(raw_data::Intersection {
.create_intersection(RawIntersection {
point,
intersection_type: IntersectionType::StopSign,
label: None,
orig_id: raw_data::OriginalIntersection {
orig_id: OriginalIntersection {
osm_node_id: self.map.new_osm_node_id(),
},
synthetic: true,
@ -341,10 +341,10 @@ impl Model {
let id = self
.map
.create_road(raw_data::Road {
.create_road(RawRoad {
i1,
i2,
orig_id: raw_data::OriginalRoad {
orig_id: OriginalRoad {
osm_way_id,
node1: self.map.intersections[&i1].orig_id.osm_node_id,
node2: self.map.intersections[&i2].orig_id.osm_node_id,
@ -633,7 +633,7 @@ impl Model {
pub fn create_b(&mut self, center: Pt2D, prerender: &Prerender) {
let id = self
.map
.create_building(raw_data::Building {
.create_building(RawBuilding {
polygon: Polygon::rectangle(center, BUILDING_LENGTH, BUILDING_LENGTH),
osm_tags: BTreeMap::new(),
osm_way_id: self.map.new_osm_way_id(),

View File

@ -1,4 +1,5 @@
use crate::{raw_data, LaneID, LaneType, Map, Road, RoadID, TurnID};
use crate::raw::StableIntersectionID;
use crate::{LaneID, LaneType, Map, Road, RoadID, TurnID};
use abstutil;
use geom::Polygon;
use serde_derive::{Deserialize, Serialize};
@ -31,7 +32,7 @@ pub struct Intersection {
pub intersection_type: IntersectionType,
pub label: Option<String>,
pub stable_id: raw_data::StableIntersectionID,
pub stable_id: StableIntersectionID,
// Note that a lane may belong to both incoming_lanes and outgoing_lanes.
// TODO narrow down when and why. is it just sidewalks in weird cases?

View File

@ -9,7 +9,7 @@ mod map;
mod neighborhood;
pub mod osm;
mod pathfind;
pub mod raw_data;
pub mod raw;
mod road;
mod stop_signs;
mod traffic_signals;

View File

@ -1,19 +1,20 @@
use crate::make::sidewalk_finder::find_sidewalk_points;
use crate::{osm, raw_data, Building, BuildingID, FrontPath, Lane, LaneID, Position, Road};
use crate::raw::{RawBuilding, StableBuildingID};
use crate::{osm, Building, BuildingID, FrontPath, Lane, LaneID, Position, Road};
use abstutil::Timer;
use geom::{Bounds, Distance, FindClosest, HashablePt2D, Line, Polygon};
use std::collections::{BTreeMap, HashSet};
pub fn make_all_buildings(
results: &mut Vec<Building>,
input: &BTreeMap<raw_data::StableBuildingID, raw_data::Building>,
input: &BTreeMap<StableBuildingID, RawBuilding>,
bounds: &Bounds,
lanes: &Vec<Lane>,
roads: &Vec<Road>,
timer: &mut Timer,
) {
timer.start("convert buildings");
let mut center_per_bldg: BTreeMap<raw_data::StableBuildingID, HashablePt2D> = BTreeMap::new();
let mut center_per_bldg: BTreeMap<StableBuildingID, HashablePt2D> = BTreeMap::new();
let mut query: HashSet<HashablePt2D> = HashSet::new();
timer.start_iter("get building center points", input.len());
for (id, b) in input {

View File

@ -1,6 +1,7 @@
use crate::raw::{RawMap, StableIntersectionID, StableRoadID};
use crate::{
make, raw_data, Area, AreaID, Building, Intersection, IntersectionID, IntersectionType, Lane,
LaneID, Road, RoadID, Turn, TurnID, LANE_THICKNESS,
make, Area, AreaID, Building, Intersection, IntersectionID, IntersectionType, Lane, LaneID,
Road, RoadID, Turn, TurnID, LANE_THICKNESS,
};
use abstutil::Timer;
use geom::{Bounds, Polygon};
@ -18,7 +19,7 @@ pub struct HalfMap {
}
pub fn make_half_map(
data: &raw_data::Map,
data: &RawMap,
initial_map: make::InitialMap,
bounds: &Bounds,
timer: &mut Timer,
@ -33,13 +34,13 @@ pub fn make_half_map(
turn_lookup: Vec::new(),
};
let road_id_mapping: BTreeMap<raw_data::StableRoadID, RoadID> = initial_map
let road_id_mapping: BTreeMap<StableRoadID, RoadID> = initial_map
.roads
.keys()
.enumerate()
.map(|(idx, id)| (*id, RoadID(idx)))
.collect();
let mut intersection_id_mapping: BTreeMap<raw_data::StableIntersectionID, IntersectionID> =
let mut intersection_id_mapping: BTreeMap<StableIntersectionID, IntersectionID> =
BTreeMap::new();
for (idx, i) in initial_map.intersections.values().enumerate() {
let raw_i = &data.intersections[&i.id];

View File

@ -1,5 +1,5 @@
use crate::make::initial::{Intersection, Road};
use crate::raw_data::{StableIntersectionID, StableRoadID};
use crate::raw::{StableIntersectionID, StableRoadID};
use abstutil::{wraparound_get, Timer, Warn};
use geom::{Distance, Line, PolyLine, Pt2D};
use std::collections::{BTreeMap, HashMap};

View File

@ -1,8 +1,8 @@
mod geometry;
pub mod lane_specs;
use crate::raw_data::{StableIntersectionID, StableRoadID};
use crate::{raw_data, IntersectionType, LaneType, LANE_THICKNESS};
use crate::raw::{RawMap, StableIntersectionID, StableRoadID};
use crate::{IntersectionType, LaneType, LANE_THICKNESS};
use abstutil::Timer;
use geom::{Bounds, Distance, PolyLine, Pt2D};
use std::collections::{BTreeMap, BTreeSet};
@ -47,12 +47,7 @@ pub struct Intersection {
}
impl InitialMap {
pub fn new(
name: String,
data: &raw_data::Map,
bounds: &Bounds,
timer: &mut Timer,
) -> InitialMap {
pub fn new(name: String, data: &RawMap, bounds: &Bounds, timer: &mut Timer) -> InitialMap {
let mut m = InitialMap {
roads: BTreeMap::new(),
intersections: BTreeMap::new(),
@ -147,10 +142,7 @@ pub struct LaneSpec {
pub reverse_pts: bool,
}
fn get_lane_specs(
osm_tags: &BTreeMap<String, String>,
id: raw_data::StableRoadID,
) -> Vec<LaneSpec> {
fn get_lane_specs(osm_tags: &BTreeMap<String, String>, id: StableRoadID) -> Vec<LaneSpec> {
let (side1_types, side2_types) = lane_specs::get_lane_types(osm_tags);
let mut specs: Vec<LaneSpec> = Vec::new();

View File

@ -1,26 +1,24 @@
use crate::raw_data;
use crate::raw::{RawMap, StableIntersectionID, StableRoadID};
use abstutil::{retain_btreemap, MultiMap, Timer};
use std::collections::HashSet;
pub fn remove_disconnected_roads(map: &mut raw_data::Map, timer: &mut Timer) {
pub fn remove_disconnected_roads(map: &mut RawMap, timer: &mut Timer) {
timer.start("removing disconnected roads");
// This is a simple floodfill, not Tarjan's. Assumes all roads bidirectional.
// All the usizes are indices into the original list of roads
let mut next_roads: MultiMap<raw_data::StableIntersectionID, raw_data::StableRoadID> =
MultiMap::new();
let mut next_roads: MultiMap<StableIntersectionID, StableRoadID> = MultiMap::new();
for (id, r) in &map.roads {
next_roads.insert(r.i1, *id);
next_roads.insert(r.i2, *id);
}
let mut partitions: Vec<Vec<raw_data::StableRoadID>> = Vec::new();
let mut unvisited_roads: HashSet<raw_data::StableRoadID> = map.roads.keys().cloned().collect();
let mut partitions: Vec<Vec<StableRoadID>> = Vec::new();
let mut unvisited_roads: HashSet<StableRoadID> = map.roads.keys().cloned().collect();
while !unvisited_roads.is_empty() {
let mut queue_roads: Vec<raw_data::StableRoadID> =
vec![*unvisited_roads.iter().next().unwrap()];
let mut current_partition: Vec<raw_data::StableRoadID> = Vec::new();
let mut queue_roads: Vec<StableRoadID> = vec![*unvisited_roads.iter().next().unwrap()];
let mut current_partition: Vec<StableRoadID> = Vec::new();
while !queue_roads.is_empty() {
let current = queue_roads.pop().unwrap();
if !unvisited_roads.contains(&current) {

View File

@ -1,10 +1,11 @@
use crate::make::get_lane_types;
use crate::pathfind::Pathfinder;
use crate::raw::{MapFixes, RawMap};
use crate::{
make, osm, raw_data, Area, AreaID, Building, BuildingID, BusRoute, BusRouteID, BusStop,
BusStopID, ControlStopSign, ControlTrafficSignal, Intersection, IntersectionID,
IntersectionType, Lane, LaneID, LaneType, MapEdits, Path, PathRequest, Position, Road, RoadID,
Turn, TurnID, TurnPriority,
make, osm, Area, AreaID, Building, BuildingID, BusRoute, BusRouteID, BusStop, BusStopID,
ControlStopSign, ControlTrafficSignal, Intersection, IntersectionID, IntersectionType, Lane,
LaneID, LaneType, MapEdits, Path, PathRequest, Position, Road, RoadID, Turn, TurnID,
TurnPriority,
};
use abstutil;
use abstutil::{deserialize_btreemap, serialize_btreemap, Error, Timer};
@ -51,8 +52,8 @@ pub struct Map {
impl Map {
pub fn new(path: &str, timer: &mut Timer) -> Result<Map, io::Error> {
let mut data: raw_data::Map = abstutil::read_binary(path, timer)?;
data.apply_fixes(&raw_data::MapFixes::load(timer), timer);
let mut data: RawMap = abstutil::read_binary(path, timer)?;
data.apply_fixes(&MapFixes::load(timer), timer);
// Do this after applying fixes, which might split off pieces of the map.
make::remove_disconnected_roads(&mut data, timer);
Ok(Map::create_from_raw(data, timer))
@ -86,7 +87,7 @@ impl Map {
}
}
fn create_from_raw(data: raw_data::Map, timer: &mut Timer) -> Map {
fn create_from_raw(data: RawMap, timer: &mut Timer) -> Map {
timer.start("raw_map to InitialMap");
let gps_bounds = data.gps_bounds.clone();
let bounds = gps_bounds.to_bounds();

View File

@ -33,13 +33,13 @@ impl fmt::Display for StableBuildingID {
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Map {
pub struct RawMap {
pub name: String,
pub roads: BTreeMap<StableRoadID, Road>,
pub intersections: BTreeMap<StableIntersectionID, Intersection>,
pub buildings: BTreeMap<StableBuildingID, Building>,
pub roads: BTreeMap<StableRoadID, RawRoad>,
pub intersections: BTreeMap<StableIntersectionID, RawIntersection>,
pub buildings: BTreeMap<StableBuildingID, RawBuilding>,
pub bus_routes: Vec<Route>,
pub areas: Vec<Area>,
pub areas: Vec<RawArea>,
// from OSM way => [(restriction, to OSM way)]
pub turn_restrictions: BTreeMap<i64, Vec<(String, i64)>>,
@ -47,9 +47,9 @@ pub struct Map {
pub gps_bounds: GPSBounds,
}
impl Map {
pub fn blank(name: String) -> Map {
Map {
impl RawMap {
pub fn blank(name: String) -> RawMap {
RawMap {
name,
roads: BTreeMap::new(),
intersections: BTreeMap::new(),
@ -204,7 +204,7 @@ impl Map {
}
// Mutations
impl Map {
impl RawMap {
pub fn delete_road(&mut self, r: StableRoadID, fixes: &mut MapFixes) {
let road = self.roads.remove(&r).unwrap();
if road.osm_tags.get(osm::SYNTHETIC) != Some(&"true".to_string()) {
@ -224,7 +224,7 @@ impl Map {
}
}
pub fn create_intersection(&mut self, i: Intersection) -> Option<StableIntersectionID> {
pub fn create_intersection(&mut self, i: RawIntersection) -> Option<StableIntersectionID> {
if self
.gps_bounds
.contains(i.point.forcibly_to_gps(&self.gps_bounds))
@ -237,7 +237,7 @@ impl Map {
}
}
pub fn create_road(&mut self, mut r: Road) -> Option<StableRoadID> {
pub fn create_road(&mut self, mut r: RawRoad) -> Option<StableRoadID> {
match (
self.find_i(OriginalIntersection {
osm_node_id: r.orig_id.node1,
@ -338,7 +338,7 @@ impl Map {
// Mutations not recorded in MapFixes yet
// TODO Fix that!
impl Map {
impl RawMap {
pub fn move_intersection(
&mut self,
id: StableIntersectionID,
@ -379,7 +379,7 @@ impl Map {
self.roads.get_mut(&id).unwrap().center_points = pts;
}
pub fn create_building(&mut self, bldg: Building) -> Option<StableBuildingID> {
pub fn create_building(&mut self, bldg: RawBuilding) -> Option<StableBuildingID> {
if bldg.polygon.center().to_gps(&self.gps_bounds).is_some() {
let id = StableBuildingID(self.buildings.keys().max().unwrap().0 + 1);
self.buildings.insert(id, bldg);
@ -406,7 +406,7 @@ impl Map {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Road {
pub struct RawRoad {
// The first and last point may not match up with i1 and i2.
pub i1: StableIntersectionID,
pub i2: StableIntersectionID,
@ -419,7 +419,7 @@ pub struct Road {
pub osm_tags: BTreeMap<String, String>,
}
impl Road {
impl RawRoad {
pub fn get_spec(&self) -> RoadSpec {
let (fwd, back) = get_lane_types(&self.osm_tags);
RoadSpec { fwd, back }
@ -427,9 +427,9 @@ impl Road {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Intersection {
pub struct RawIntersection {
// Represents the original place where OSM center-lines meet. This is meaningless beyond
// raw_data; roads and intersections get merged and deleted.
// RawMap; roads and intersections get merged and deleted.
pub point: Pt2D,
pub intersection_type: IntersectionType,
pub label: Option<String>,
@ -438,7 +438,7 @@ pub struct Intersection {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Building {
pub struct RawBuilding {
pub polygon: Polygon,
pub osm_tags: BTreeMap<String, String>,
pub osm_way_id: i64,
@ -446,7 +446,7 @@ pub struct Building {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Area {
pub struct RawArea {
pub area_type: AreaType,
pub polygon: Polygon,
pub osm_tags: BTreeMap<String, String>,
@ -476,13 +476,13 @@ pub struct OriginalIntersection {
pub osm_node_id: i64,
}
// Directives from the map_editor crate to apply to the raw_data layer.
// Directives from the map_editor crate to apply to the RawMap layer.
#[derive(Serialize, Deserialize, Clone)]
pub struct MapFixes {
pub delete_roads: Vec<OriginalRoad>,
pub delete_intersections: Vec<OriginalIntersection>,
pub add_intersections: Vec<Intersection>,
pub add_roads: Vec<Road>,
pub add_intersections: Vec<RawIntersection>,
pub add_roads: Vec<RawRoad>,
pub merge_short_roads: Vec<OriginalRoad>,
// For non-synthetic (original OSM) roads
pub override_tags: BTreeMap<OriginalRoad, BTreeMap<String, String>>,

View File

@ -1,4 +1,5 @@
use crate::{osm, raw_data, BusStopID, IntersectionID, LaneID, LaneType, Map, LANE_THICKNESS};
use crate::raw::StableRoadID;
use crate::{osm, BusStopID, IntersectionID, LaneID, LaneType, Map, LANE_THICKNESS};
use abstutil::{Error, Warn};
use geom::{Distance, PolyLine, Polygon, Speed};
use serde_derive::{Deserialize, Serialize};
@ -63,7 +64,7 @@ pub struct Road {
// self is 'from'
pub turn_restrictions: Vec<(String, RoadID)>,
pub osm_way_id: i64,
pub stable_id: raw_data::StableRoadID,
pub stable_id: StableRoadID,
// Invariant: A road must contain at least one child
// These are ordered from left-most lane (closest to center lane) to rightmost (sidewalk)