-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcsv_to_html.py
90 lines (72 loc) · 2.05 KB
/
csv_to_html.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -*- coding: utf-8 -*-
"""
Plot all SnapperGPS tracks in a folder on an HTML map.
Expect SnapperGPS tracks in CSV files.
Exclude fixes without confidence.
Map can be displayed in a browser.
@author: Jonas Beuchert
"""
import folium
import numpy as np
import glob
import os
# Centre of map (latitude and longitude in decimal degrees)
pos_ref_geo = np.array([15.215534, -23.152380])
# Create map
m = folium.Map(
location=[pos_ref_geo[0], pos_ref_geo[1]],
# tiles='http://tile.stamen.com/terrain-background/{z}/{x}/{y}.png',
attr=' ',
control_scale=True,
zoom_control=False,
tiles='OpenStreetMap', # 'Stamen Toner' 'Stamen Terrain' 'Mapbox Bright' 'Mapbox Control Room'
zoom_start=13
)
# Files to display (adjust path to files, if necessary)
files = glob.glob(os.path.join("", "*.csv"))
# Color map
colors = [
'red',
'blue',
'black',
'darkred',
'lightred',
'purple',
'orange',
'beige',
'green',
'darkgreen',
'darkblue',
'lightgreen',
'darkpurple',
'pink',
'cadetblue',
'lightgray',
'black'
]
colors = colors[:len(files)]
# Loop over all CSV files
for path, color in zip(files, colors):
label = path[:-4]
print(f"Process file {label}.")
if len(path) > 0:
# Load estimated positions
lats, lons = np.loadtxt(path, delimiter=',',
skiprows=1, usecols=[1, 2], unpack=True)
confidences = np.loadtxt(path, delimiter=',', dtype=str,
skiprows=1, usecols=[3], unpack=True)
lats = lats[confidences != ""]
lons = lons[confidences != ""]
track = [(lat, lon) for lat, lon in zip(lats, lons)]
# Draw track as polyline
folium.PolyLine(track,
color=color,
weight=3,
opacity=0.4,
popup=label,
# dash_array='10'
).add_to(m)
# Save map as HTML file
m.save("all_tracks.html")
print('Saved locations on map as HTML file.')
print()