-
Notifications
You must be signed in to change notification settings - Fork 0
/
running.py
60 lines (46 loc) · 1.66 KB
/
running.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import argparse
from pathlib import Path
import gpxpy
import matplotlib.pyplot as plt
import mplleaflet
import pandas as pd
from tqdm import tqdm
def visualize_routes(data_dir, map_file):
map_file_dir = map_file.parent
map_file_dir.mkdir(parents=True, exist_ok=True)
gpx_files = list(data_dir.glob("*.gpx"))
gpx_files_count = len(gpx_files)
points = []
for gpx_file in tqdm(gpx_files, desc=f"{'Extract routes data': <20}"):
with open(gpx_file, "r") as f:
gpx_data = gpxpy.parse(f)
data = gpx_data.tracks[0].segments[0].points
for point in data:
points.append(
{
"file_name": gpx_file.name,
"lon": point.longitude,
"lat": point.latitude,
"alt": point.elevation,
"time": point.time,
}
)
df = pd.DataFrame(points)
routes = df.groupby("file_name")
fig = plt.figure()
for _, route_df in tqdm(
routes, desc=f"{'Plot routes': <20}", total=gpx_files_count
):
route_df = route_df.sort_values("time")
plt.plot(route_df["lon"], route_df["lat"], linewidth=3)
mplleaflet.show(fig=fig, path=map_file)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="GPX routes visualization")
parser.add_argument("--data", type=str, required=True, help="folder with GPX files")
parser.add_argument(
"--map", type=str, required=True, help="path to the output map file"
)
args = parser.parse_args()
data_dir = Path(args.data)
map_file = Path(args.map)
visualize_routes(data_dir, map_file)