|
|
@@ -10,38 +10,49 @@ use std;
|
|
10
|
10
|
/// An OpenStreetMap node element from a compressed array of DenseNodes (See [OSM wiki](http://wiki.openstreetmap.org/wiki/Node)).
|
|
11
|
11
|
pub struct DenseNode<'a> {
|
|
12
|
12
|
block: &'a osmformat::PrimitiveBlock,
|
|
|
13
|
+
|
|
|
14
|
+ /// The node id. It should be unique between nodes and might be negative to indicate
|
|
|
15
|
+ /// that the element has not yet been uploaded to a server.
|
|
13
|
16
|
pub id: i64,
|
|
|
17
|
+ /// The version of this element.
|
|
14
|
18
|
pub version: i32,
|
|
15
|
19
|
timestamp: i64,
|
|
|
20
|
+ /// The changeset id.
|
|
16
|
21
|
pub changeset: i64,
|
|
|
22
|
+ /// The user id.
|
|
17
|
23
|
pub uid: i32,
|
|
18
|
|
- pub user_sid: i32,
|
|
|
24
|
+ user_sid: i32,
|
|
19
|
25
|
lat: i64,
|
|
20
|
26
|
lon: i64,
|
|
21
|
27
|
keys_vals_indices: &'a [i32],
|
|
22
|
28
|
}
|
|
23
|
29
|
|
|
24
|
30
|
impl<'a> DenseNode<'a> {
|
|
|
31
|
+ /// Returns the user name.
|
|
25
|
32
|
pub fn user(&self) -> Result<&'a str> {
|
|
26
|
33
|
str_from_stringtable(self.block, self.user_sid as usize)
|
|
27
|
34
|
}
|
|
28
|
35
|
|
|
|
36
|
+ /// Returns the latitude coordinate in degrees.
|
|
29
|
37
|
pub fn lat(&self) -> f64 {
|
|
30
|
38
|
0.000_000_001_f64 * (self.block.get_lat_offset() +
|
|
31
|
39
|
(i64::from(self.block.get_granularity()) *
|
|
32
|
40
|
self.lat)) as f64
|
|
33
|
41
|
}
|
|
34
|
42
|
|
|
|
43
|
+ /// Returns the longitude coordinate in degrees.
|
|
35
|
44
|
pub fn lon(&self) -> f64 {
|
|
36
|
45
|
0.000_000_001_f64 * (self.block.get_lon_offset() +
|
|
37
|
46
|
(i64::from(self.block.get_granularity()) *
|
|
38
|
47
|
self.lon)) as f64
|
|
39
|
48
|
}
|
|
40
|
49
|
|
|
|
50
|
+ /// Returns the time stamp in milliseconds since the epoch.
|
|
41
|
51
|
pub fn milli_timestamp(&self) -> i64 {
|
|
42
|
52
|
self.timestamp * i64::from(self.block.get_date_granularity())
|
|
43
|
53
|
}
|
|
44
|
54
|
|
|
|
55
|
+ /// Returns an iterator over the tags of this way (See [OSM wiki](http://wiki.openstreetmap.org/wiki/Tags)).
|
|
45
|
56
|
pub fn tags(&self) -> DenseTagIter<'a> {
|
|
46
|
57
|
DenseTagIter {
|
|
47
|
58
|
block: self.block,
|
|
|
@@ -50,6 +61,7 @@ impl<'a> DenseNode<'a> {
|
|
50
|
61
|
}
|
|
51
|
62
|
}
|
|
52
|
63
|
|
|
|
64
|
+/// An iterator over dense nodes. It decodes the delta encoded values.
|
|
53
|
65
|
pub struct DenseNodeIter<'a> {
|
|
54
|
66
|
block: &'a osmformat::PrimitiveBlock,
|
|
55
|
67
|
dids: std::slice::Iter<'a, i64>, // deltas
|
|
|
@@ -72,7 +84,7 @@ pub struct DenseNodeIter<'a> {
|
|
72
|
84
|
}
|
|
73
|
85
|
|
|
74
|
86
|
impl<'a> DenseNodeIter<'a> {
|
|
75
|
|
- pub fn new(block: &'a osmformat::PrimitiveBlock,
|
|
|
87
|
+ pub(crate) fn new(block: &'a osmformat::PrimitiveBlock,
|
|
76
|
88
|
osmdense: &'a osmformat::DenseNodes) -> DenseNodeIter<'a> {
|
|
77
|
89
|
let info = osmdense.get_denseinfo();
|
|
78
|
90
|
DenseNodeIter {
|
|
|
@@ -164,6 +176,7 @@ impl<'a> Iterator for DenseNodeIter<'a> {
|
|
164
|
176
|
|
|
165
|
177
|
impl<'a> ExactSizeIterator for DenseNodeIter<'a> {}
|
|
166
|
178
|
|
|
|
179
|
+/// An iterator over the tags in a dense node.
|
|
167
|
180
|
pub struct DenseTagIter<'a> {
|
|
168
|
181
|
block: &'a osmformat::PrimitiveBlock,
|
|
169
|
182
|
keys_vals_indices: std::slice::Iter<'a, i32>,
|