-
Notifications
You must be signed in to change notification settings - Fork 0
/
testgpx.py
61 lines (43 loc) · 1.27 KB
/
testgpx.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
import gpxpy
import gpxpy.gpx
import sys
import myexif
import os
#Options:
# GPX
# time offset
# photos path
# photo to beused for sync of times
def loadgpx(name):
gpx_file = open(name, 'rb')
gpx = gpxpy.parse(gpx_file)
md = None
a = []
for track in gpx.tracks:
for segment in track.segments:
for point in segment.points:
if md is None:
md = point.time
print 'Point at @{3} ({0},{1}) -> {2} d {4}'.format(point.latitude, point.longitude, point.elevation,point.time,point.time-md)
md = point.time
a.append(md)
return a
# build an index out of the time and
def find_lt(a, x):
'Find rightmost value less than x'
i = bisect_left(a, x)
if i:
return a[i-1]
raise ValueError
# for every photo extract time, adjust offset and find nearest point
# then propose position or rewrite
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Sync photos to GPX')
parser.add_argument('--gpx', help='path to the GPX')
parser.add_argument('--offset',type=int, help='offset in seconds to be added TO photos to sync')
parser.add_argument('--path',help='path of the photos')
args = parser.parse_args()
# extract photo times
# load path
track = loadgpx(args.gpx)