longitude and lattitude can be accessed

This commit is contained in:
dongho
2024-09-06 01:47:14 +09:00
parent 43817cfeea
commit 419b830acf
2 changed files with 40 additions and 23 deletions

View File

@ -1,31 +1,17 @@
use std::fmt::write;
use osmpbf::*;
fn main() {
let reader = ElementReader::from_path(
"/mnt/c/Users/dongho/Desktop/ekstrahMap/assets/south-korea-latest.osm.pbf",
);
println!("Counting...");
match reader.expect("REASON").par_map_reduce(
|element| match element {
Element::Node(_) | Element::DenseNode(_) => (1, 0, 0),
Element::Way(_) => (0, 1, 0),
Element::Relation(_) => (0, 0, 1),
},
|| (0u64, 0u64, 0u64),
|a, b| (a.0 + b.0, a.1 + b.1, a.2 + b.2),
) {
Ok((nodes, ways, relations)) => {
println!("Nodes: {nodes}");
println!("Ways: {ways}");
println!("Relations: {relations}");
let mut nodes = 0_u64;
let _ = reader.expect("REASON").for_each(|element| {
if let Element::DenseNode(node) = element {
let lat: f64 = node.lat();
let lon: f64 = node.lon();
let id: i64 = node.id();
println!("Node: {id}, Latitude: {lat}, Longitude: {lon}");
}
Err(e) => {
println!("{e}");
std::process::exit(1);
}
}
});
println!("Number of ways: {nodes}");
}

31
src/main2.rs Normal file
View File

@ -0,0 +1,31 @@
use std::fmt::write;
use osmpbf::*;
fn main() {
let reader = ElementReader::from_path(
"/mnt/c/Users/dongho/Desktop/ekstrahMap/assets/south-korea-latest.osm.pbf",
);
println!("Counting...");
match reader.expect("REASON").par_map_reduce(
|element| match element {
Element::Node(_) | Element::DenseNode(_) => (1, 0, 0),
Element::Way(_) => (0, 1, 0),
Element::Relation(_) => (0, 0, 1),
},
|| (0u64, 0u64, 0u64),
|a, b| (a.0 + b.0, a.1 + b.1, a.2 + b.2),
) {
Ok((nodes, ways, relations)) => {
println!("Nodes: {nodes}");
println!("Ways: {ways}");
println!("Relations: {relations}");
}
Err(e) => {
println!("{e}");
std::process::exit(1);
}
}
}