waypoints from gmaps
parent
9650cb0204
commit
a255fc5c1e
|
|
@ -1,16 +1,21 @@
|
||||||
|
|
||||||
- it is becoming messy
|
- direction is still shitty on gps
|
||||||
- split on points with comments
|
- split on points with comments
|
||||||
|
and encode them as waypoints
|
||||||
|
|
||||||
|
- code is becoming messy
|
||||||
|
|
||||||
- turn off gps when moving to next waypoint
|
- turn off gps when moving to next waypoint
|
||||||
|
- display distance to next water/toilet
|
||||||
|
|
||||||
- meters seem to be a bit too long
|
- meters seem to be a bit too long
|
||||||
|
|
||||||
- buzzing does not work nicely
|
- buzzing does not work nicely
|
||||||
-> is_lost seems fishy
|
-> is_lost seems fishy
|
||||||
|
-> we need a display on top of buzz
|
||||||
|
|
||||||
- display average speed
|
- display average speed
|
||||||
- dynamic map rescale
|
- dynamic map rescale
|
||||||
- display scale (100m)
|
- display scale (100m)
|
||||||
|
|
||||||
- compress path
|
- compress path ?
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,7 @@ impl Point {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn points(filename: &str) -> impl Iterator<Item = Point> {
|
fn points(filename: &str) -> Vec<Vec<Point>> {
|
||||||
// This XML file actually exists — try it for yourself!
|
|
||||||
let file = File::open(filename).unwrap();
|
let file = File::open(filename).unwrap();
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
|
|
@ -67,15 +66,38 @@ fn points(filename: &str) -> impl Iterator<Item = Point> {
|
||||||
let mut gpx: Gpx = read(reader).unwrap();
|
let mut gpx: Gpx = read(reader).unwrap();
|
||||||
eprintln!("we have {} tracks", gpx.tracks.len());
|
eprintln!("we have {} tracks", gpx.tracks.len());
|
||||||
|
|
||||||
gpx.tracks
|
let mut points = Vec::new();
|
||||||
|
|
||||||
|
let mut iter = gpx
|
||||||
|
.tracks
|
||||||
.pop()
|
.pop()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.segments
|
.segments
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|segment| segment.linestring().points().collect::<Vec<_>>())
|
.flat_map(|segment| segment.points.into_iter())
|
||||||
.map(|point| (point.x(), point.y()))
|
.map(|p| {
|
||||||
.dedup()
|
let geop = p.point();
|
||||||
.map(|(x, y)| Point { x, y })
|
(
|
||||||
|
Point {
|
||||||
|
x: geop.x(),
|
||||||
|
y: geop.y(),
|
||||||
|
},
|
||||||
|
p.comment.is_some(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.dedup();
|
||||||
|
let mut current_segment = iter.next().map(|(p, _)| p).into_iter().collect::<Vec<_>>();
|
||||||
|
for (p, is_waypoint) in iter {
|
||||||
|
if is_waypoint {
|
||||||
|
points.push(current_segment);
|
||||||
|
current_segment = Vec::new();
|
||||||
|
}
|
||||||
|
current_segment.push(p);
|
||||||
|
}
|
||||||
|
let last_point = current_segment.pop();
|
||||||
|
points.push(current_segment);
|
||||||
|
points.extend(last_point.map(|p| vec![p]));
|
||||||
|
points
|
||||||
}
|
}
|
||||||
|
|
||||||
// // NOTE: this angles idea could maybe be use to get dp from n^3 to n^2
|
// // NOTE: this angles idea could maybe be use to get dp from n^3 to n^2
|
||||||
|
|
@ -363,6 +385,17 @@ fn save_gpc<P: AsRef<Path>>(path: P, points: &[Point], buckets: &[Bucket]) -> st
|
||||||
.flat_map(|p| [p.point.x, p.point.y])
|
.flat_map(|p| [p.point.x, p.point.y])
|
||||||
.try_for_each(|c| writer.write_all(&c.to_le_bytes()))?;
|
.try_for_each(|c| writer.write_all(&c.to_le_bytes()))?;
|
||||||
|
|
||||||
|
let counts: HashMap<_, usize> =
|
||||||
|
unique_interest_points
|
||||||
|
.iter()
|
||||||
|
.fold(HashMap::new(), |mut h, p| {
|
||||||
|
*h.entry(p.interest).or_default() += 1;
|
||||||
|
h
|
||||||
|
});
|
||||||
|
counts.into_iter().for_each(|(interest, count)| {
|
||||||
|
eprintln!("{:?} appears {} times", interest, count);
|
||||||
|
});
|
||||||
|
|
||||||
unique_interest_points
|
unique_interest_points
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| p.interest.into())
|
.map(|p| p.interest.into())
|
||||||
|
|
@ -378,8 +411,6 @@ fn save_gpc<P: AsRef<Path>>(path: P, points: &[Point], buckets: &[Bucket]) -> st
|
||||||
.map(|b| b.start as u16)
|
.map(|b| b.start as u16)
|
||||||
.try_for_each(|i| writer.write_all(&i.to_le_bytes()))?;
|
.try_for_each(|i| writer.write_all(&i.to_le_bytes()))?;
|
||||||
|
|
||||||
let starts: Vec<_> = buckets.iter().map(|b| b.start).collect();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -512,18 +543,10 @@ fn save_svg<'a, P: AsRef<Path>, I: IntoIterator<Item = &'a InterestPoint>>(
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let rpoints = rp.iter().cloned().collect::<HashSet<_>>();
|
waypoints.iter().try_for_each(|p| {
|
||||||
waypoints.difference(&rpoints).try_for_each(|p| {
|
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut writer,
|
&mut writer,
|
||||||
"<circle cx='{}' cy='{}' fill='red' r='1%'/>",
|
"<circle cx='{}' cy='{}' fill='black' r='1%'/>",
|
||||||
p.x, p.y,
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
waypoints.intersection(&rpoints).try_for_each(|p| {
|
|
||||||
writeln!(
|
|
||||||
&mut writer,
|
|
||||||
"<circle cx='{}' cy='{}' fill='green' r='1%'/>",
|
|
||||||
p.x, p.y,
|
p.x, p.y,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -611,19 +634,33 @@ fn position_interests_along_path(
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let input_file = std::env::args().nth(1).unwrap_or("m.gpx".to_string());
|
let input_file = std::env::args().nth(1).unwrap_or("m.gpx".to_string());
|
||||||
eprintln!("input is {}", input_file);
|
eprintln!("input is {}", input_file);
|
||||||
let p = points(&input_file).collect::<Vec<_>>();
|
let mut segmented_points = points(&input_file);
|
||||||
eprintln!("initialy we have {} points", p.len());
|
let p = segmented_points
|
||||||
let start = std::time::Instant::now();
|
.iter()
|
||||||
let rp = simplify_path(&p, 0.00015);
|
.flatten()
|
||||||
let waypoints = detect_waypoints(&rp);
|
.copied()
|
||||||
eprintln!("we took {:?}", start.elapsed());
|
.collect::<Vec<_>>();
|
||||||
eprintln!("we now have {} points", rp.len());
|
|
||||||
let start = std::time::Instant::now();
|
|
||||||
eprintln!("rdp would have had {}", rdp(&p, 0.00015).len());
|
|
||||||
eprintln!("rdp took {:?}", start.elapsed());
|
|
||||||
|
|
||||||
let mut interests = parse_osm_data("isere.osm.pbf");
|
eprintln!("initialy we have {} points", p.len());
|
||||||
let buckets = position_interests_along_path(&mut interests, &rp, 0.0005, 5, 3);
|
|
||||||
|
eprintln!("we have {} waypoints", segmented_points.len());
|
||||||
|
|
||||||
|
let mut waypoints = HashSet::new();
|
||||||
|
let mut rp = Vec::new();
|
||||||
|
for (i1, i2) in (0..segmented_points.len()).tuple_windows() {
|
||||||
|
if let [s1, s2] = &mut segmented_points[i1..=i2] {
|
||||||
|
s1.extend(s2.first().copied());
|
||||||
|
waypoints.insert(s1.first().copied().unwrap());
|
||||||
|
let mut simplified = simplify_path(&s1, 0.00015);
|
||||||
|
rp.append(&mut simplified);
|
||||||
|
rp.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rp.extend(segmented_points.last().and_then(|l| l.last()).copied());
|
||||||
|
|
||||||
|
let mut interests = parse_osm_data("ardeche.osm.pbf");
|
||||||
|
// let mut interests = parse_osm_data("isere.osm.pbf");
|
||||||
|
let buckets = position_interests_along_path(&mut interests, &rp, 0.001, 5, 3);
|
||||||
// let i = get_openstreetmap_data(&rp).await;
|
// let i = get_openstreetmap_data(&rp).await;
|
||||||
// let i = HashSet::new();
|
// let i = HashSet::new();
|
||||||
save_svg(
|
save_svg(
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,14 @@ pub enum Interest {
|
||||||
Bakery,
|
Bakery,
|
||||||
DrinkingWater,
|
DrinkingWater,
|
||||||
Toilets,
|
Toilets,
|
||||||
BikeShop,
|
// BikeShop,
|
||||||
ChargingStation,
|
// ChargingStation,
|
||||||
Bank,
|
// Bank,
|
||||||
Supermarket,
|
// Supermarket,
|
||||||
Table,
|
// Table,
|
||||||
// TourismOffice,
|
// TourismOffice,
|
||||||
Artwork,
|
Artwork,
|
||||||
Pharmacy,
|
// Pharmacy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<u8> for Interest {
|
impl Into<u8> for Interest {
|
||||||
|
|
@ -31,13 +31,13 @@ impl Into<u8> for Interest {
|
||||||
Interest::Bakery => 0,
|
Interest::Bakery => 0,
|
||||||
Interest::DrinkingWater => 1,
|
Interest::DrinkingWater => 1,
|
||||||
Interest::Toilets => 2,
|
Interest::Toilets => 2,
|
||||||
Interest::BikeShop => 3,
|
// Interest::BikeShop => 3,
|
||||||
Interest::ChargingStation => 4,
|
// Interest::ChargingStation => 4,
|
||||||
Interest::Bank => 5,
|
// Interest::Bank => 5,
|
||||||
Interest::Supermarket => 6,
|
// Interest::Supermarket => 6,
|
||||||
Interest::Table => 7,
|
// Interest::Table => 7,
|
||||||
Interest::Artwork => 8,
|
Interest::Artwork => 8,
|
||||||
Interest::Pharmacy => 9,
|
// Interest::Pharmacy => 9,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -54,14 +54,14 @@ lazy_static! {
|
||||||
(("shop", "bakery"), Interest::Bakery),
|
(("shop", "bakery"), Interest::Bakery),
|
||||||
(("amenity", "drinking_water"), Interest::DrinkingWater),
|
(("amenity", "drinking_water"), Interest::DrinkingWater),
|
||||||
(("amenity", "toilets"), Interest::Toilets),
|
(("amenity", "toilets"), Interest::Toilets),
|
||||||
(("shop", "bicycle"), Interest::BikeShop),
|
// (("shop", "bicycle"), Interest::BikeShop),
|
||||||
(("amenity", "charging_station"), Interest::ChargingStation),
|
// (("amenity", "charging_station"), Interest::ChargingStation),
|
||||||
(("amenity", "bank"), Interest::Bank),
|
// (("amenity", "bank"), Interest::Bank),
|
||||||
(("shop", "supermarket"), Interest::Supermarket),
|
// (("shop", "supermarket"), Interest::Supermarket),
|
||||||
(("leisure", "picnic_table"), Interest::Table),
|
// (("leisure", "picnic_table"), Interest::Table),
|
||||||
// (("tourism", "information"), Interest::TourismOffice),
|
// (("tourism", "information"), Interest::TourismOffice),
|
||||||
(("tourism", "artwork"), Interest::Artwork),
|
(("tourism", "artwork"), Interest::Artwork),
|
||||||
(("amenity", "pharmacy"), Interest::Pharmacy),
|
// (("amenity", "pharmacy"), Interest::Pharmacy),
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect()
|
.collect()
|
||||||
|
|
@ -80,13 +80,13 @@ impl InterestPoint {
|
||||||
Interest::Bakery => "red",
|
Interest::Bakery => "red",
|
||||||
Interest::DrinkingWater => "blue",
|
Interest::DrinkingWater => "blue",
|
||||||
Interest::Toilets => "brown",
|
Interest::Toilets => "brown",
|
||||||
Interest::BikeShop => "purple",
|
// Interest::BikeShop => "purple",
|
||||||
Interest::ChargingStation => "green",
|
// Interest::ChargingStation => "green",
|
||||||
Interest::Bank => "black",
|
// Interest::Bank => "black",
|
||||||
Interest::Supermarket => "red",
|
// Interest::Supermarket => "red",
|
||||||
Interest::Table => "pink",
|
// Interest::Table => "pink",
|
||||||
Interest::Artwork => "orange",
|
Interest::Artwork => "orange",
|
||||||
Interest::Pharmacy => "chartreuse",
|
// Interest::Pharmacy => "chartreuse",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue