-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
63 lines (59 loc) · 2.55 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use georender_pack::{encode,Member,MemberType,MemberRole};
use hex;
use osmpbf::{Element, ElementReader};
use std::collections::HashMap;
use std::env;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let args: Vec<String> = env::args().collect();
let reader = ElementReader::from_path(&args[1]).unwrap();
let mut nodes: HashMap<u64, (f32, f32)> = HashMap::new();
let mut ways: HashMap<u64, Vec<u64>> = HashMap::new();
reader.for_each(|item| {
match item {
Element::DenseNode(node) => {
let point = (node.lon() as f32, node.lat() as f32);
nodes.insert(node.id as u64, point);
let tags = node.tags().into_iter().collect::<Vec<_>>();
let encoded = encode::node(node.id as u64, point, &tags).unwrap();
println!("{}", hex::encode(encoded));
},
Element::Node(node) => {
let point = (node.lon() as f32, node.lat() as f32);
nodes.insert(node.id() as u64, point);
let tags = node.tags().into_iter().collect::<Vec<_>>();
let encoded = encode::node(node.id() as u64, point, &tags).unwrap();
println!("{}", hex::encode(encoded));
},
Element::Relation(rel) => {
let tags = rel.tags().into_iter().collect::<Vec<_>>();
let members = rel.members().map(|m| convert_member(&m)).collect::<Vec<_>>();
let encoded = encode::relation(rel.id() as u64, &tags, &members, &nodes, &ways).unwrap();
println!("{}", hex::encode(encoded));
},
Element::Way(way) => {
let tags = way.tags().into_iter().collect::<Vec<_>>();
let refs = way.refs().map(|r| r as u64).collect::<Vec<u64>>();
ways.insert(way.id() as u64, refs.clone());
let encoded = encode::way(way.id() as u64, &tags, &refs, &nodes).unwrap();
println!("{}", hex::encode(encoded));
}
}
}).unwrap();
Ok(())
}
fn convert_member(m: &osmpbf::RelMember) -> Member {
Member::new(
m.member_id as u64,
match m.role().unwrap() {
"inner" => MemberRole::Inner(),
"outer" => MemberRole::Outer(),
_ => MemberRole::Unused(),
},
match m.member_type {
osmpbf::RelMemberType::Node => MemberType::Node(),
osmpbf::RelMemberType::Way => MemberType::Way(),
osmpbf::RelMemberType::Relation => MemberType::Relation(),
}
)
}