-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateLocationInfo.py
More file actions
55 lines (43 loc) · 1.64 KB
/
CreateLocationInfo.py
File metadata and controls
55 lines (43 loc) · 1.64 KB
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
import os
import sys
import glob
import gpxpy
import cPickle
class CreateLocationInfo(object):
"""
Time, Latitude, Longitude, Altitude
"""
def __init__(self, file_path):
self._file_path = file_path
self._location_info = []
def run(self):
if os.path.isdir(self._file_path):
file_path_list = glob.glob(os.path.join(self._file_path, "*.gpx"))
elif os.path.isfile(self._file_path):
file_path_list = [self._file_path]
else:
sys.exit(1)
for file_path in file_path_list:
print file_path
if os.path.basename(file_path).split('.')[1] == 'dump':
self.get_dump_data(file_path)
else:
self.get_location_info(file_path)
self._location_info.sort()
return self._location_info
def get_dump_data(self, file_path):
with open(file_path, 'r') as fd:
self._location_info += cPickle.load(fd)
def get_location_info(self, file_path):
gpx_data = open(file_path, 'r')
gpx = gpxpy.parse(gpx_data)
for track in gpx.tracks:
for segment in track.segments:
for point in segment.points:
self._location_info.append([point.time, point.latitude, point.longitude, point.elevation])
if __name__ == '__main__':
#location_info = CreateLocationInfo('/Users/anhm/Desktop/path/location.dump').run()
location_info = CreateLocationInfo('/Users/anhm/Desktop/path').run()
print len(location_info)
with open('/Users/anhm/Desktop/path/location.dump', 'w') as fd:
cPickle.dump(location_info, fd)