@@ -37,7 +37,7 @@ def resource_path(relative_path):
3737from . import gpshelper
3838from . import VERSION
3939
40- def BuildGPSPoints (data , skip = False , skipDop = False , dopLimit = 2000 ):
40+ def BuildGPSPoints (data , skip = False , skipDop = False , dopLimit = 2000 , timeShift = 0 ):
4141 """
4242 Procesa los datos extraídos y genera una lista de puntos GPS.
4343
@@ -64,6 +64,7 @@ def BuildGPSPoints(data, skip=False, skipDop=False, dopLimit=2000):
6464 DVNM = "Unknown"
6565
6666 for d in data :
67+ # print("fourCC: {}".format(d.fourCC))
6768 if d .fourCC == 'SCAL' :
6869 SCAL = d .data
6970 elif d .fourCC == "DVNM" :
@@ -103,9 +104,8 @@ def BuildGPSPoints(data, skip=False, skipDop=False, dopLimit=2000):
103104 continue
104105 retdata = [ float (x ) / float (y ) for x ,y in zip (item ._asdict ().values (), list (SCAL )) ]
105106 gpsdata = fourCC .GPSData ._make (retdata )
106- p = gpshelper .GPSPoint (gpsdata .lat , gpsdata .lon , gpsdata .alt ,
107- GPSU + datetime .timedelta (seconds = sample_count * t_delta ),
108- gpsdata .speed , 'GPS5' )
107+ gpstime = GPSU + datetime .timedelta (seconds = sample_count * t_delta ) + datetime .timedelta (seconds = timeShift )
108+ p = gpshelper .GPSPoint (gpsdata .lat , gpsdata .lon , gpsdata .alt , gpstime , gpsdata .speed , 'GPS5' )
109109 points .append (p )
110110 stats ['ok' ] += 1
111111 sample_count += 1
@@ -133,7 +133,7 @@ def BuildGPSPoints(data, skip=False, skipDop=False, dopLimit=2000):
133133 gpsdata = fourCC .GPS9Data ._make (retdata )
134134 target_date = datetime .datetime (2000 , 1 , 1 ) + datetime .timedelta (days = gpsdata .days_since_2000 )
135135 time_of_day = datetime .timedelta (seconds = gpsdata .secs_since_midnight )
136- gps_time = target_date + time_of_day
136+ gps_time = ( target_date + time_of_day ) - datetime . timedelta ( seconds = 3600 ) - datetime . timedelta ( seconds = timeShift )
137137 if start_time is None :
138138 start_time = gps_time
139139 p = gpshelper .GPSPoint (gpsdata .lat , gpsdata .lon , gpsdata .alt , gps_time , gpsdata .speed , 'GPS9' )
@@ -157,8 +157,8 @@ def BuildGPSPoints(data, skip=False, skipDop=False, dopLimit=2000):
157157 data_vals = [ float (x ) / float (y ) for x ,y in zip (d .data ._asdict ().values (), list (SCAL )) ]
158158 gpsdata = fourCC .KARMAGPSData ._make (data_vals )
159159 if SYST .seconds != 0 and SYST .miliseconds != 0 :
160- p = gpshelper . GPSPoint ( gpsdata . lat , gpsdata . lon , gpsdata . alt ,
161- datetime . datetime . fromtimestamp ( SYST . miliseconds ) , gpsdata .speed )
160+ syst_time = datetime . datetime . fromtimestamp ( SYST . miliseconds ) - datetime . timedelta ( seconds = timeShift )
161+ p = gpshelper . GPSPoint ( gpsdata . lat , gpsdata . lon , gpsdata . alt , syst_time , gpsdata .speed )
162162 points .append (p )
163163 stats ['ok' ] += 1
164164 elif d .fourCC == 'GPSP' :
@@ -175,8 +175,12 @@ def BuildGPSPoints(data, skip=False, skipDop=False, dopLimit=2000):
175175 print ("- Empty (No data): %5d" % stats ['empty' ])
176176 print ("Total points: %5d" % total_points )
177177 print ("--------------------------" )
178+ if timeShift > 0 :
179+ print (f"Timestamp shifted: { timeShift } s" )
180+ start_time = start_time - datetime .timedelta (seconds = timeShift )
178181 return (points , start_time , DVNM )
179182
183+
180184def parseArgs ():
181185 version_text = f"gopro2gpx version { VERSION } "
182186 parser = argparse .ArgumentParser ()
@@ -185,6 +189,7 @@ def parseArgs():
185189 parser .add_argument ("-s" , "--skip" , help = "Skip bad points (GPSFIX=0)" , action = "store_true" , default = False )
186190 parser .add_argument ("--skip-dop" , help = "Skip high Dilution of Precision points (GPSP>X)" , action = "store_true" , default = False )
187191 parser .add_argument ("--dop-limit" , help = "Dilution of Precision limit" , default = 2000 , type = int )
192+ parser .add_argument ("--time-shift" , help = "Shift Timestamps by X seconds" , default = 0 , type = int )
188193 parser .add_argument ("--gpx" , help = "Generate only GPX output" , action = "store_true" , default = False )
189194 parser .add_argument ("--kml" , help = "Generate only KML output" , action = "store_true" , default = False )
190195 parser .add_argument ("--csv" , help = "Generate only CSV output" , action = "store_true" , default = False )
@@ -222,7 +227,7 @@ def main_core(args):
222227 f .write (raw_data )
223228 data += gpmf .parseStream (raw_data , config .verbose )
224229
225- points , start_time , device_name = BuildGPSPoints (data , skip = args .skip , skipDop = args .skip_dop , dopLimit = args .dop_limit )
230+ points , start_time , device_name = BuildGPSPoints (data , skip = args .skip , skipDop = args .skip_dop , dopLimit = args .dop_limit , timeShift = args . time_shift )
226231 if len (points ) == 0 :
227232 print ("Can't create file. No GPS info in %s. Exiting" % args .files )
228233 if not args .gui :
0 commit comments