mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-27 00:12:55 +03:00
finish producing the osm change
This commit is contained in:
parent
76f5dc21be
commit
1fc9792378
@ -82,3 +82,12 @@ ffmpeg -f x11grab -r 25 -s 1800x800 -i :0.0+28,92 -vcodec huffyuv raw.avi
|
|||||||
|
|
||||||
ffmpeg -ss 10.0 -t 5.0 -i raw.avi -f gif -filter_complex "[0:v] fps=12,scale=1024:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" screencast.gif
|
ffmpeg -ss 10.0 -t 5.0 -i raw.avi -f gif -filter_complex "[0:v] fps=12,scale=1024:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" screencast.gif
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## JOSM
|
||||||
|
|
||||||
|
```
|
||||||
|
java -jar ~/Downloads/josm-tested.jar ~/abstreet/map_editor/parking_diff.osc
|
||||||
|
```
|
||||||
|
|
||||||
|
Press (and release T), then click to pan. Download a relevant layer, select the
|
||||||
|
.osc, merge, then upload.
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use map_model::osm;
|
use map_model::osm;
|
||||||
use map_model::raw::RawMap;
|
use map_model::raw::RawMap;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
pub fn find_parking_diffs(map: &RawMap) {
|
pub fn find_parking_diffs(map: &RawMap) {
|
||||||
let mut way_to_tags: BTreeMap<String, BTreeMap<String, String>> = BTreeMap::new();
|
let mut way_to_tags: BTreeMap<String, BTreeMap<String, String>> = BTreeMap::new();
|
||||||
@ -18,12 +20,8 @@ pub fn find_parking_diffs(map: &RawMap) {
|
|||||||
way_to_tags.insert(tags[osm::OSM_WAY_ID].clone(), tags);
|
way_to_tags.insert(tags[osm::OSM_WAY_ID].clone(), tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (way, tags) in way_to_tags {
|
let mut modified_ways = Vec::new();
|
||||||
println!("grab way {}", way);
|
for (way, abst_tags) in way_to_tags {
|
||||||
for (k, v) in tags {
|
|
||||||
println!(" - {} = {}", k, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
let url = format!("https://api.openstreetmap.org/api/0.6/way/{}", way);
|
let url = format!("https://api.openstreetmap.org/api/0.6/way/{}", way);
|
||||||
println!("Fetching {}", url);
|
println!("Fetching {}", url);
|
||||||
let resp = reqwest::get(&url).unwrap().text().unwrap();
|
let resp = reqwest::get(&url).unwrap().text().unwrap();
|
||||||
@ -31,26 +29,64 @@ pub fn find_parking_diffs(map: &RawMap) {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.take_child("way")
|
.take_child("way")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
for elem in &tree.children {
|
let mut osm_tags = BTreeMap::new();
|
||||||
|
let mut other_children = Vec::new();
|
||||||
|
for elem in tree.children.drain(..) {
|
||||||
if elem.name == "tag" {
|
if elem.name == "tag" {
|
||||||
println!(
|
osm_tags.insert(elem.attributes["k"].clone(), elem.attributes["v"].clone());
|
||||||
"attribs: {} = {}",
|
} else {
|
||||||
elem.attributes["k"], elem.attributes["v"]
|
other_children.push(elem);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Does the data already match?
|
||||||
|
if abst_tags.get(osm::PARKING_LEFT) == osm_tags.get(osm::PARKING_LEFT)
|
||||||
|
&& abst_tags.get(osm::PARKING_RIGHT) == osm_tags.get(osm::PARKING_RIGHT)
|
||||||
|
&& abst_tags.get(osm::PARKING_BOTH) == osm_tags.get(osm::PARKING_BOTH)
|
||||||
|
{
|
||||||
|
println!("{} is already up-to-date in OSM", way);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill out these tags.
|
||||||
|
for tag_key in vec![osm::PARKING_LEFT, osm::PARKING_RIGHT, osm::PARKING_BOTH] {
|
||||||
|
if let Some(value) = abst_tags.get(tag_key) {
|
||||||
|
osm_tags.insert(tag_key.to_string(), value.to_string());
|
||||||
|
} else {
|
||||||
|
osm_tags.remove(tag_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tree.children = other_children;
|
||||||
|
for (k, v) in osm_tags {
|
||||||
|
let mut new_elem = xmltree::Element::new("tag");
|
||||||
|
new_elem.attributes.insert("k".to_string(), k);
|
||||||
|
new_elem.attributes.insert("v".to_string(), v);
|
||||||
|
tree.children.push(new_elem);
|
||||||
|
}
|
||||||
|
|
||||||
tree.attributes.remove("timestamp");
|
tree.attributes.remove("timestamp");
|
||||||
tree.attributes.remove("changeset");
|
tree.attributes.remove("changeset");
|
||||||
tree.attributes.remove("user");
|
tree.attributes.remove("user");
|
||||||
tree.attributes.remove("uid");
|
tree.attributes.remove("uid");
|
||||||
tree.attributes.remove("visible");
|
tree.attributes.remove("visible");
|
||||||
// TODO bump version
|
|
||||||
|
|
||||||
let mut bytes: Vec<u8> = Vec::new();
|
let mut bytes: Vec<u8> = Vec::new();
|
||||||
tree.write(&mut bytes).unwrap();
|
tree.write(&mut bytes).unwrap();
|
||||||
let out = String::from_utf8(bytes).unwrap();
|
let out = String::from_utf8(bytes).unwrap();
|
||||||
let stripped = out.trim_start_matches("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
let stripped = out.trim_start_matches("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
|
modified_ways.push(stripped.to_string());
|
||||||
println!("wrote: {}", stripped);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("{} modified ways", modified_ways.len());
|
||||||
|
if modified_ways.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let path = "parking_diff.osc";
|
||||||
|
let mut f = File::create(path).unwrap();
|
||||||
|
writeln!(f, "<osmChange version=\"0.6\" generator=\"abst\"><modify>").unwrap();
|
||||||
|
for w in modified_ways {
|
||||||
|
writeln!(f, " {}", w).unwrap();
|
||||||
|
}
|
||||||
|
writeln!(f, "</modify></osmChange>").unwrap();
|
||||||
|
println!("Wrote {}", path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user