|
|
@@ -1,8 +1,7 @@
|
|
1
|
1
|
//! High level reader interface
|
|
2
|
2
|
|
|
3
|
3
|
use blob::{BlobDecode, BlobReader};
|
|
4
|
|
-use dense::DenseNode;
|
|
5
|
|
-use elements::{Node, Way, Relation};
|
|
|
4
|
+use elements::Element;
|
|
6
|
5
|
use errors::*;
|
|
7
|
6
|
use rayon::prelude::*;
|
|
8
|
7
|
use std::fs::File;
|
|
|
@@ -74,20 +73,7 @@ impl<R: Read> ElementReader<R> {
|
|
74
|
73
|
match blob.decode() {
|
|
75
|
74
|
Ok(BlobDecode::OsmHeader(_)) | Ok(BlobDecode::Unknown(_)) => {},
|
|
76
|
75
|
Ok(BlobDecode::OsmData(block)) => {
|
|
77
|
|
- for group in block.groups() {
|
|
78
|
|
- for node in group.nodes() {
|
|
79
|
|
- f(Element::Node(node))
|
|
80
|
|
- }
|
|
81
|
|
- for dnode in group.dense_nodes() {
|
|
82
|
|
- f(Element::DenseNode(dnode))
|
|
83
|
|
- }
|
|
84
|
|
- for way in group.ways() {
|
|
85
|
|
- f(Element::Way(way));
|
|
86
|
|
- }
|
|
87
|
|
- for relation in group.relations() {
|
|
88
|
|
- f(Element::Relation(relation));
|
|
89
|
|
- }
|
|
90
|
|
- }
|
|
|
76
|
+ block.for_each_element(&mut f);
|
|
91
|
77
|
},
|
|
92
|
78
|
Err(e) => return Err(e),
|
|
93
|
79
|
}
|
|
|
@@ -189,29 +175,8 @@ impl ElementReader<BufReader<File>> {
|
|
189
|
175
|
/// ```
|
|
190
|
176
|
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>
|
|
191
|
177
|
{
|
|
192
|
|
- let f = File::open(path)?;
|
|
193
|
|
- let reader = BufReader::new(f);
|
|
194
|
|
-
|
|
195
|
178
|
Ok(ElementReader {
|
|
196
|
|
- blob_iter: BlobReader::new(reader),
|
|
|
179
|
+ blob_iter: BlobReader::from_path(path)?,
|
|
197
|
180
|
})
|
|
198
|
181
|
}
|
|
199
|
182
|
}
|
|
200
|
|
-
|
|
201
|
|
-/// An enum with the OSM core elements: nodes, ways and relations.
|
|
202
|
|
-#[derive(Clone, Debug)]
|
|
203
|
|
-pub enum Element<'a> {
|
|
204
|
|
- /// A node. Also, see `DenseNode`.
|
|
205
|
|
- Node(Node<'a>),
|
|
206
|
|
-
|
|
207
|
|
- /// Just like `Node`, but with a different representation in memory. This distinction is
|
|
208
|
|
- /// usually not important but is not abstracted away to avoid copying. So, if you want to match
|
|
209
|
|
- /// `Node`, you also likely want to match `DenseNode`.
|
|
210
|
|
- DenseNode(DenseNode<'a>),
|
|
211
|
|
-
|
|
212
|
|
- /// A way.
|
|
213
|
|
- Way(Way<'a>),
|
|
214
|
|
-
|
|
215
|
|
- /// A relation.
|
|
216
|
|
- Relation(Relation<'a>),
|
|
217
|
|
-}
|