-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpx_mapper.py
36 lines (28 loc) · 928 Bytes
/
gpx_mapper.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
# -*- coding: utf-8 -*-
import gpxpy
import gpxpy.gpx
from folium import Map, PolyLine
from os.path import join
from os import walk
GPX_INPUT_DIR = './GPX/Berlin'
HTML_OUT_FILE = './gpx_berlin.html'
MAP_CENTER = [52.5200, 13.4050]
MAP_ZOOM = 11
def read_gpx(file):
gpx_file = open(file, 'r')
gpx = gpxpy.parse(gpx_file)
points = []
for track in gpx.tracks:
for segment in track.segments:
for point in segment.points:
points.append(tuple([point.latitude, point.longitude]))
return points
my_map = Map(location=MAP_CENTER, MAP_ZOOM=11)
for (dirpath, dirnames, filenames) in walk(GPX_INPUT_DIR):
for file in filenames:
file = join(dirpath, file)
points = read_gpx(file)
PolyLine(points, color="blue", weight=5, opacity=0.5).add_to(my_map)
print('Reading',file)
print('Writing', HTML_OUT_FILE)
my_map.save(HTML_OUT_FILE)