Skip to content

Commit

Permalink
Version 4.1.0: add option to delete waypoints
Browse files Browse the repository at this point in the history
- implements #147
- Added waypoints are now more likely to be selected for the Excel export
  • Loading branch information
wp99cp authored May 30, 2024
2 parents d778893 + 539392e commit 52290cb
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from typing import List

import numpy as np

from automatic_walk_time_tables.path_transformers.path_transfomer import PathTransformer
from automatic_walk_time_tables.utils.path import Path

from automatic_walk_time_tables.utils.geometry_utils import (
calc_secant_line,
calc_secant_elevation,
)
from automatic_walk_time_tables.utils.path import Path
from automatic_walk_time_tables.utils.way_point import WayPoint


Expand Down Expand Up @@ -59,7 +59,32 @@ def transform(self, path: Path):
self.__logger.debug("Total distance: %f km", path.total_distance)

way_points = self.replace_with_close_by_pois(way_points, path)
way_points = self.add_pois(way_points)

return way_points

def add_pois(self, way_points: Path) -> Path:
"""
Add POIs to the way_points if they are at least 50 meters apart from any other point.
And if the max number of points is not reached.
"""

for poi in self.pois.way_points:

if way_points.number_of_waypoints >= self.number_of_waypoints:
break

if any(
abs(poi.accumulated_distance - p.accumulated_distance) < 50
for p in way_points.way_points
):
continue
way_points.insert(poi)

# Drop Point's close to each other
self.drop_points(5, Path(), way_points, True)
return way_points

def replace_with_close_by_pois(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

import numpy as np

from automatic_walk_time_tables.path_transformers.path_transfomer import PathTransformer
from automatic_walk_time_tables.utils.path import Path
from automatic_walk_time_tables.utils.point import Point_LV95
Expand All @@ -25,7 +24,6 @@ def transform(self, path: Path) -> Path:
elif self.pois_list_as_str != "":
return self.pois_from_string(path)

# TODO: calc points of interest if list is empty
else:
return self.calc_pois(path)

Expand Down Expand Up @@ -95,8 +93,20 @@ def calc_pois(self, path: Path):
# calc extremums of path_
max_index = np.argmax([p.point.h for p in path.way_points])
min_index = np.argmin([p.point.h for p in path.way_points])
pois.insert(path.way_points[max_index])
pois.insert(path.way_points[min_index])

# we add extremums to the list of points of interest if they are at least 100m away from the endpoint
if (
path.way_points[max_index].point.distance(path.way_points[0].point) >= 100
and path.way_points[min_index].point.distance(path.way_points[0].point)
>= 100
):
pois.insert(path.way_points[max_index])
if (
path.way_points[min_index].point.distance(path.way_points[-1].point) >= 100
and path.way_points[max_index].point.distance(path.way_points[-1].point)
>= 100
):
pois.insert(path.way_points[min_index])

# add endpoint to list of points of interest
pois.append(path.way_points[-1])
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
A complete, technical changelog is available at [GitHub](https://github.com/cevi/automatic_walk-time_tables/releases).

## Version 4 - Improved Error handling & drop CLI support
- Add option to delete waypoints (4.1.0)
- Added waypoints are now more likely to be selected for the Excel export (4.1.0)
- Error messages are better shown to the user (4.0.0)
- CLI support is fully dropped (4.0.0)
- Map numbers computation uses less API requests (4.0.0)
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automatic-walk-time-tables",
"version": "4.0.3",
"version": "4.1.0",
"scripts": {
"ng": "ng",
"start": "tsc set-env.ts && BACKEND_DOMAIN=http://localhost:5000 node set-env.js && angular-build-info && ng serve",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<span class="action-description"> Drag-and-Drop GPX- / KML-Datei </span>
<span class="small-font"> oder </span>

<button mat-stroked-button color="primary" class="select-file" > GPX- / KML-Datei auswählen </button>
<input type="file" id="uploader" accept=".gpx,.kml" (input)="file_added($event)">
<button mat-stroked-button color="primary" class="select-file" (click)="fileSelect.click()"> GPX- / KML-Datei auswählen </button>
<input type="file" id="uploader" accept=".gpx,.kml" (input)="file_added($event)" #fileSelect>

</div>
13 changes: 13 additions & 0 deletions frontend/src/app/services/map-animator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,18 @@ export class MapAnimatorService {

}

public delete_poi(point: LV95_Waypoint) {

this.pois$.pipe(take(1)).subscribe(pois => {
this._pois$.next(pois.filter(p => p.x != point.x || p.y != point.y));
});

combineLatest([this._path$, this._pois$, this.way_points$]).pipe(take(1))
.subscribe(([path, pois, way_points]) =>
this.create_walk_time_table(path, pois).catch(err => this._error_handler(err))
);

}


}
62 changes: 52 additions & 10 deletions frontend/src/app/services/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class MapService extends SwisstopoMap {
private pointer: number[] | undefined | null;
private map_animator: MapAnimatorService | undefined;


public link_animator(map_animator: MapAnimatorService) {

this.map_animator = map_animator;
Expand Down Expand Up @@ -105,7 +106,6 @@ export class MapService extends SwisstopoMap {

});


combineLatest([map_animator.way_points$, map_animator.pois$])
.subscribe(([way_points, pois]) => {

Expand All @@ -114,11 +114,12 @@ export class MapService extends SwisstopoMap {
way_points.forEach(way_point => {

const feature = new Feature({
geometry: new Circle([way_point.x, way_point.y], 25)
geometry: new Circle([way_point.x, way_point.y], 10)
});

feature.setStyle(new Style({
stroke: new Stroke({color: '#f13c3c', width: 5})
fill: new Fill({color: '#fff'}),
stroke: new Stroke({color: '#EFA038', width: 8}),
}));

this.way_points_layer_source.addFeature(feature);
Expand All @@ -129,14 +130,18 @@ export class MapService extends SwisstopoMap {
pois.forEach(way_point => {

const feature = new Feature({
geometry: new Circle([way_point.x, way_point.y], 30)
geometry: new Circle([way_point.x, way_point.y], 10)
});

// check if the poi is actually selected
const is_selected = way_points.find(p => p.x == way_point.x && p.y == way_point.y) != undefined;

feature.setStyle(new Style({
stroke: new Stroke({color: '#2043d7', width: 5}),
fill: new Fill({color: '#fff'}),
stroke: is_selected ? new Stroke({color: '#2043d7', width: 8}) : new Stroke({color: '#2043d750', width: 8}) ,
text: new Text({
text: way_point.name,
fill: new Fill({color: '#f13c3c'}),
fill: new Fill({color: '#2043d7'}),
font: 'bold 16px Open Sans'
})
}));
Expand Down Expand Up @@ -174,23 +179,59 @@ export class MapService extends SwisstopoMap {

this.map?.on('pointermove', async (evt) => {

const [nearest_point, dist] = await this.get_nearest_way_point(evt);
const [nearest_point, dist] = await this.get_nearest_path_point(evt);
if (dist <= 50 && nearest_point) this.map_animator?.move_pointer(nearest_point);
else this.map_animator?.move_pointer(null);

});

this.map?.on('click', async (evt) => {

const [nearest_point, dist] = await this.get_nearest_way_point(evt);
if (dist <= 50 && nearest_point) this.map_animator?.add_point_of_interest(nearest_point);
const [nearest_point, dist] = await this.get_nearest_path_point(evt);
const [nearest_poi, dist_poi] = await this.get_nearest_poi(evt);

if (dist <= 50 && nearest_point && dist_poi >= 50) this.map_animator?.add_point_of_interest(nearest_point);
else if (dist_poi <= 50 && nearest_poi) this.map_animator?.delete_poi(nearest_poi);


});

}

private async get_nearest_poi(event: MapBrowserEvent<any>): Promise<[LV95_Waypoint | null, number]> {

const p = event.coordinate;

if (this.map_animator == undefined) return [null, Infinity];

return new Promise((resolve, _) => {

if (this.map_animator == undefined) return resolve([null, Infinity]);

this.map_animator?.pois$.pipe(take(1))
.subscribe((pois) => {

if (pois.length == 0) return resolve([null, Infinity]);

// get the coordinates of the point neares to the p
const nearest_point = pois.reduce((prev, curr) => {
const prev_dist = Math.sqrt(Math.pow(prev.x - p[0], 2) + Math.pow(prev.y - p[1], 2));
const curr_dist = Math.sqrt(Math.pow(curr.x - p[0], 2) + Math.pow(curr.y - p[1], 2));
return prev_dist < curr_dist ? prev : curr;
});

const dist = Math.sqrt(Math.pow(nearest_point.x - p[0], 2) + Math.pow(nearest_point.y - p[1], 2));

resolve([nearest_point, dist])

});

});

}


private async get_nearest_way_point(event: MapBrowserEvent<any>): Promise<[LV95_Waypoint | null, number]> {
private async get_nearest_path_point(event: MapBrowserEvent<any>): Promise<[LV95_Waypoint | null, number]> {

const p = event.coordinate;

Expand Down Expand Up @@ -219,6 +260,7 @@ export class MapService extends SwisstopoMap {

}


private render_pointer(wmtsLayer: Tile<WMTS>) {

const radius = 12;
Expand Down

0 comments on commit 52290cb

Please sign in to comment.