mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
start remembering osm_node_ids for intersections
This commit is contained in:
parent
b3bfd6a3f2
commit
1e73baa078
@ -16,6 +16,8 @@ pub fn extract_osm(
|
||||
Vec<raw_data::Road>,
|
||||
// Traffic signals
|
||||
HashSet<HashablePt2D>,
|
||||
// OSM Node IDs
|
||||
HashMap<HashablePt2D, i64>,
|
||||
) {
|
||||
let (reader, done) = FileWithProgress::new(osm_path).unwrap();
|
||||
let doc = osm_xml::OSM::parse(reader).expect("OSM parsing failed");
|
||||
@ -41,16 +43,18 @@ 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 traffic_signals: HashSet<HashablePt2D> = HashSet::new();
|
||||
let mut osm_node_ids = HashMap::new();
|
||||
|
||||
timer.start_iter("processing OSM nodes", doc.nodes.len());
|
||||
for node in doc.nodes.values() {
|
||||
timer.next();
|
||||
let pt =
|
||||
Pt2D::forcibly_from_gps(LonLat::new(node.lon, node.lat), &map.gps_bounds).to_hashable();
|
||||
osm_node_ids.insert(pt, node.id);
|
||||
|
||||
let tags = tags_to_map(&node.tags);
|
||||
if tags.get(osm::HIGHWAY) == Some(&"traffic_signals".to_string()) {
|
||||
traffic_signals.insert(
|
||||
Pt2D::forcibly_from_gps(LonLat::new(node.lon, node.lat), &map.gps_bounds)
|
||||
.to_hashable(),
|
||||
);
|
||||
traffic_signals.insert(pt);
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,7 +197,7 @@ pub fn extract_osm(
|
||||
}
|
||||
}
|
||||
|
||||
(map, roads, traffic_signals)
|
||||
(map, roads, traffic_signals, osm_node_ids)
|
||||
}
|
||||
|
||||
fn tags_to_map(raw_tags: &[osm_xml::Tag]) -> BTreeMap<String, String> {
|
||||
|
@ -4,10 +4,11 @@ use map_model::{osm, raw_data, IntersectionType};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub fn split_up_roads(
|
||||
(mut map, mut roads, traffic_signals): (
|
||||
(mut map, mut roads, traffic_signals, osm_node_ids): (
|
||||
raw_data::Map,
|
||||
Vec<raw_data::Road>,
|
||||
HashSet<HashablePt2D>,
|
||||
HashMap<HashablePt2D, i64>,
|
||||
),
|
||||
timer: &mut Timer,
|
||||
) -> raw_data::Map {
|
||||
@ -50,6 +51,7 @@ pub fn split_up_roads(
|
||||
},
|
||||
label: None,
|
||||
synthetic: false,
|
||||
osm_node_id: osm_node_ids[pt],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -403,6 +403,7 @@ pub struct Intersection {
|
||||
pub label: Option<String>,
|
||||
pub orig_id: OriginalIntersection,
|
||||
pub synthetic: bool,
|
||||
pub osm_node_id: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
@ -219,6 +219,28 @@ impl Model {
|
||||
}
|
||||
|
||||
pub fn create_i(&mut self, point: Pt2D, prerender: &Prerender) {
|
||||
// Since these are negative, they shouldn't conflict with OSM IDs.
|
||||
let mut osm_node_id = -1
|
||||
* (std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs() as i64);
|
||||
// Silly edge case: creating many intersections in the same second. ;)
|
||||
loop {
|
||||
let mut ok = true;
|
||||
for i in self.map.intersections.values() {
|
||||
if i.osm_node_id == osm_node_id {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ok {
|
||||
break;
|
||||
} else {
|
||||
osm_node_id -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
let id = self
|
||||
.map
|
||||
.create_intersection(raw_data::Intersection {
|
||||
@ -229,6 +251,7 @@ impl Model {
|
||||
point: point.forcibly_to_gps(&self.map.gps_bounds),
|
||||
},
|
||||
synthetic: true,
|
||||
osm_node_id,
|
||||
})
|
||||
.unwrap();
|
||||
self.intersection_added(id, prerender);
|
||||
|
Loading…
Reference in New Issue
Block a user