1
0
Fork 0

bugfix in sharp turns detect

master
frederic wagner 2022-08-23 11:19:19 +02:00
parent 5147008f00
commit f533887975
4 changed files with 4 additions and 931 deletions

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,5 @@ edition = "2021"
[dependencies]
gpx="*"
itertools="*"
openstreetmap-api="*"
tokio={version="1", features=["full"]}
lazy_static="*"
osmio="*"

View File

@ -11,7 +11,7 @@ use gpx::Gpx;
mod osm;
use osm::{parse_osm_data, InterestPoint};
const LOWER_SHARP_TURN: f64 = 45.0 * std::f64::consts::PI / 180.0;
const LOWER_SHARP_TURN: f64 = 80.0 * std::f64::consts::PI / 180.0;
const UPPER_SHARP_TURN: f64 = std::f64::consts::PI * 2.0 - LOWER_SHARP_TURN;
const KEY: u16 = 47490;
@ -633,7 +633,7 @@ fn detect_sharp_turns(path: &[Point], waypoints: &mut HashSet<Point>) {
} else {
adiff
};
(adiff % std::f64::consts::PI, b)
(adiff, b)
})
.filter_map(|(adiff, b)| {
if adiff > LOWER_SHARP_TURN && adiff < UPPER_SHARP_TURN {
@ -647,8 +647,7 @@ fn detect_sharp_turns(path: &[Point], waypoints: &mut HashSet<Point>) {
});
}
#[tokio::main]
async fn main() {
fn main() {
let input_file = std::env::args().nth(1).unwrap_or("m.gpx".to_string());
let osm_file = std::env::args().nth(2);

View File

@ -1,10 +1,6 @@
use super::Point;
use itertools::Itertools;
use lazy_static::lazy_static;
use openstreetmap_api::{
types::{BoundingBox, Credentials},
Openstreetmap,
};
use osmio::OSMObjBase;
use osmio::{prelude::*, ObjId};
use std::collections::{HashMap, HashSet};
@ -91,65 +87,6 @@ impl InterestPoint {
}
}
async fn get_openstreetmap_data(points: &[(f64, f64)]) -> HashSet<InterestPoint> {
let osm = Openstreetmap::new("https://openstreetmap.org", Credentials::None);
let mut interest_points = HashSet::new();
let border = 0.0001;
let mut boxes = Vec::new();
let max_size = 0.005;
points.iter().fold(
(std::f64::MAX, std::f64::MIN, std::f64::MAX, std::f64::MIN),
|in_box, &(x, y)| {
let (mut xmin, mut xmax, mut ymin, mut ymax) = in_box;
xmin = xmin.min(x);
xmax = xmax.max(x);
ymin = ymin.min(y);
ymax = ymax.max(y);
if (xmax - xmin > max_size) || (ymax - ymin > max_size) {
boxes.push(in_box);
(x, x, y, y)
} else {
(xmin, xmax, ymin, ymax)
}
},
);
eprintln!("we need {} requests to openstreetmap", boxes.len());
for (xmin, xmax, ymin, ymax) in boxes {
let left = xmin - border;
let right = xmax + border;
let bottom = ymin - border;
let top = ymax + border;
match osm
.map(&BoundingBox {
bottom,
left,
top,
right,
})
.await
{
Ok(map) => {
let points = map.nodes.iter().flat_map(|n| {
n.tags.iter().filter_map(|t| {
let latlon = n.lat.and_then(|lat| n.lon.map(|lon| (lat, lon)));
latlon.and_then(|(lat, lon)| {
Interest::new(&t.k, &t.v).map(|i| InterestPoint {
point: Point { x: lon, y: lat },
interest: i,
})
})
})
});
interest_points.extend(points)
}
Err(e) => {
eprintln!("failed retrieving osm data: {:?}", e);
}
}
}
interest_points
}
pub fn parse_osm_data<P: AsRef<Path>>(path: P) -> Vec<InterestPoint> {
let reader = osmio::read_pbf(path).ok();
reader