o5m_stream/
data.rs

1#[derive(Clone,PartialEq,Debug)]
2pub enum Dataset {
3  Node(Node),
4  Way(Way),
5  Relation(Relation),
6  BBox(BBox),
7  Timestamp(Timestamp),
8}
9impl Dataset {
10  pub fn get_id(&self) -> Option<u64> {
11    match self {
12      Self::Node(node) => Some(node.id),
13      Self::Way(way) => Some(way.id),
14      Self::Relation(relation) => Some(relation.id),
15      _ => None,
16    }
17  }
18  pub fn get_info(&self) -> Option<Info> {
19    match self {
20      Self::Node(node) => node.info.clone(),
21      Self::Way(way) => way.info.clone(),
22      Self::Relation(relation) => relation.info.clone(),
23      _ => None,
24    }
25  }
26}
27
28#[derive(Clone,PartialEq,Debug)]
29pub enum DatasetType {
30  Node(), Way(), Relation(), BBox(), Timestamp(),
31  Header(), Sync(), Jump(), Reset(),
32}
33
34#[derive(Clone,PartialEq,Debug)]
35pub enum ElementType {
36  Node(), Way(), Relation(),
37}
38
39pub type Tags = std::collections::HashMap<String,String>;
40
41pub trait Element {
42  fn get_id(&self) -> u64;
43  fn get_info(&'_ self) -> Option<&'_ Info>;
44  fn get_type(&self) -> ElementType;
45  fn get_tags(&'_ self) -> &'_ Tags;
46}
47
48#[derive(Clone,PartialEq,Debug)]
49pub struct Info {
50  pub version: Option<u64>,
51  pub timestamp: Option<i64>,
52  pub changeset: Option<u64>,
53  pub uid: Option<u64>,
54  pub user: Option<String>,
55}
56impl Info {
57  pub fn new() -> Self {
58    Self {
59      version: None,
60      timestamp: None,
61      changeset: None,
62      uid: None,
63      user: None
64    }
65  }
66}
67
68impl Default for Info {
69  fn default() -> Self { Self::new() }
70}
71
72#[derive(Clone,PartialEq,Debug)]
73pub struct Node {
74  pub id: u64,
75  pub info: Option<Info>,
76  pub data: Option<NodeData>,
77  pub tags: Tags,
78}
79#[derive(Clone,PartialEq,Debug)]
80pub struct NodeData {
81  pub longitude: i32,
82  pub latitude: i32,
83}
84impl NodeData {
85  pub fn get_longitude(&self) -> f32 {
86    (self.longitude as f32) / 1.0e7
87  }
88  pub fn get_latitude(&self) -> f32 {
89    (self.latitude as f32) / 1.0e7
90  }
91}
92impl Element for Node {
93  fn get_id(&self) -> u64 { self.id }
94  fn get_info(&'_ self) -> Option<&'_ Info> {
95    self.info.as_ref()
96  }
97  fn get_type(&self) -> ElementType { ElementType::Node() }
98  fn get_tags(&'_ self) -> &'_ Tags { &self.tags }
99}
100
101#[derive(Clone,PartialEq,Debug)]
102pub struct Way {
103  pub id: u64,
104  pub info: Option<Info>,
105  pub data: Option<WayData>,
106  pub tags: Tags,
107}
108#[derive(Clone,PartialEq,Debug)]
109pub struct WayData {
110  pub refs: Vec<u64>
111}
112impl Element for Way {
113  fn get_id(&self) -> u64 { self.id }
114  fn get_info(&'_ self) -> Option<&'_ Info> {
115    self.info.as_ref()
116  }
117  fn get_type(&self) -> ElementType { ElementType::Way() }
118  fn get_tags(&'_ self) -> &'_ Tags { &self.tags }
119}
120
121#[derive(Clone,PartialEq,Debug)]
122pub struct Relation {
123  pub id: u64,
124  pub info: Option<Info>,
125  pub data: Option<RelationData>,
126  pub tags: Tags,
127}
128#[derive(Clone,PartialEq,Debug)]
129pub struct RelationData {
130  pub members: Vec<RelationMember>
131}
132#[derive(Clone,PartialEq,Debug)]
133pub struct RelationMember {
134  pub id: u64,
135  pub element_type: ElementType,
136  pub role: String,
137}
138impl Element for Relation {
139  fn get_id(&self) -> u64 { self.id }
140  fn get_info(&'_ self) -> Option<&'_ Info> {
141    self.info.as_ref()
142  }
143  fn get_type(&self) -> ElementType { ElementType::Relation() }
144  fn get_tags(&'_ self) -> &'_ Tags { &self.tags }
145}
146
147#[derive(Clone,PartialEq,Debug)]
148pub struct BBox {
149  pub x1: i32,
150  pub y1: i32,
151  pub x2: i32,
152  pub y2: i32,
153}
154impl BBox {
155  pub fn get_x1(&self) -> f32 { self.x1 as f32 / 1.0e7 }
156  pub fn get_y1(&self) -> f32 { self.y1 as f32 / 1.0e7 }
157  pub fn get_x2(&self) -> f32 { self.x2 as f32 / 1.0e7 }
158  pub fn get_y2(&self) -> f32 { self.y2 as f32 / 1.0e7 }
159  pub fn get_bounds(&self) -> (f32,f32,f32,f32) {
160    (self.get_x1(),self.get_y1(),self.get_x2(),self.get_y2())
161  }
162}
163
164#[derive(Clone,PartialEq,Debug)]
165pub struct Timestamp {
166  pub time: i64,
167}