-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpxfile.py
91 lines (62 loc) · 2.05 KB
/
gpxfile.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
91
"""webnote.GPXFILE. Classes exploiting spatial data in gpx files.
"""
import gpxpy
import os
class GPXFile():
"""Class to handle a gpx file.
Provide methods to display the data inside a gpx file. Lists of
routes, tracks, and waypoints.
"""
gpx = None # Parsed gpxpy object.
warnings = []
def __init__(self, gpxfile):
"""Parse the file with gpxpy.
Consumes an element from gpxpy, or an opened file. Returns a
dictionary of gps data values.
"""
self.gpxfile = gpxfile
self.gpx = gpxpy.parse(gpxfile)
def analyse(self):
"""Return a dictionary containing lists of routes, tracks and
waypoints .
"""
(path, name) = os.path.split(self.gpxfile.name)
result = {
"name": name,
"routes": self.analyse_routes(),
"tracks": self.analyse_tracks(),
"waypoints": self.analyse_waypoints(),
}
return result
def analyse_routes(self):
"""List basic data about each route."""
result = []
return result
def analyse_tracks(self):
"""List basic data about each track."""
result = []
for track in self.gpx.tracks:
points = 0
for segment in track.segments:
points += len(segment.points)
trackrec = {
"name": track.name,
"segments": len(track.segments),
"points": points,
}
result.append(trackrec)
return result
def analyse_waypoints(self):
"""List basic data about each waypoint."""
result = []
for waypoint in self.gpx.waypoints:
point = {
"name": waypoint.name,
"comment": waypoint.comment,
"latitude": waypoint.latitude,
"longitude": waypoint.longitude,
"elevation": waypoint.elevation,
"time": waypoint.time,
}
result.append(point)
return result