Created
February 19, 2019 03:39
-
-
Save ivder/4e807b8f2de64fe5d283770ee1bc7183 to your computer and use it in GitHub Desktop.
Convert the GPS data that extracted from GoPro Camera to NMEA-GPRMC format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import time | |
import datetime | |
import csv | |
import os | |
def lat_lon(n): | |
a,b=divmod(n,1) | |
total=(a*100)+(b*60) | |
return format(total, '.5f') | |
def gps_simulation(csvfile,filelist,dirlist): | |
record=[] #original | |
newrecord=[] #1 second 1 coordinate | |
firstsec=0 | |
if not os.path.exists(dirlist): | |
os.makedirs(dirlist) | |
file = open(dirlist+"/"+filelist+"_NMEA.txt","w") | |
'''with open(csvfile,'rb') as f: | |
reader=csv.reader(f) | |
for _ in range(7): | |
next(reader) | |
for row in reader: | |
record.append(map(float,row)) | |
firstsec=record[0][0] | |
newrecord.append(record[0]) | |
for i in record: | |
tempsec=i[0] | |
if tempsec-firstsec >= 1: | |
newrecord.append(i) | |
firstsec=i[0] | |
for j in newrecord: | |
times=datetime.datetime.utcfromtimestamp(j[0]).strftime('%H%M%S.00') | |
date=datetime.datetime.utcfromtimestamp(j[0]).strftime("%d%m%Y") | |
date=date[:-4]+date[-2:] | |
speed=j[4] * 1.943846 | |
lat=lat_lon(j[1]) | |
lon=lat_lon(j[2]) | |
file.write('$GPRMC,'+str(times)+',A,'+str(lat)+',N,'+str(lon)+',E,'+str(speed)+',,'+str(date)+',,,A*74\n')''' | |
with open(csvfile,'rb') as f: | |
reader=csv.reader(f) | |
for row in reader: | |
del row[-1] | |
record.append(map(float,row)) | |
'''firstsec=record[0][0] | |
newrecord.append(record[0]) | |
for i in record: | |
tempsec=i[0] | |
if tempsec-firstsec >= 1: | |
newrecord.append(i) | |
firstsec=i[0]''' | |
for j in record: | |
#print j | |
times=datetime.datetime.utcfromtimestamp(j[0]).strftime('%H%M%S.00') | |
date=datetime.datetime.utcfromtimestamp(j[0]).strftime("%d%m%Y") | |
date=date[:-4]+date[-2:] | |
speed=j[4] * 1.943846 | |
lat=lat_lon(j[1]) | |
lon=lat_lon(j[2]) | |
file.write('$GPRMC,'+str(times)+',A,'+str(lat)+',N,'+str(lon)+',E,'+str(speed)+',,'+str(date)+',,,A*74\n') | |
file.close() | |
#main | |
for root, dirs, files in os.walk(".\csv\gunpo"): | |
for filelist in files: | |
if filelist.endswith(".csv"): | |
csvfile=os.path.join(root, filelist) | |
dirlist=os.path.basename(os.path.normpath(root)) | |
gps_simulation(csvfile,filelist,dirlist) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment