Skip to content

Instantly share code, notes, and snippets.

@barend
Created August 3, 2014 18:46
Show Gist options
  • Save barend/085f5c9a7a0f14a54c11 to your computer and use it in GitHub Desktop.
Save barend/085f5c9a7a0f14a54c11 to your computer and use it in GitHub Desktop.
Process GPS log of Sony camera
# Sony camera emits GPS data in NMEA format [1]
#
# The $GPRMC records contain velocity
#
# $GPRMC,043151.097,A,5203.5674,N,513.4071,E,14.56,,010814,,,A*43
# ^ ^ ^ ^ ^ ^ ^
# | | | | | | \-Checksum
# | | | | | |
# | | | | | \- date, ddmmyy
# | | | | \-------- velocity in knots
# | | | \------------------- longitude: 4º51.2579E
# | | \------------------------------- latitude: 52º23.1071'N
# | \--------------------------------- status, active or void
# \-------------------------------------------- time hhmmss in UTC
#
#
# [1]: http://www.gpsinformation.org/dale/nmea.htm
# Output date in "ddmmyyHHMMSS+0000" format
# This drops the milliseconds, but the equipment isn't all that accurate anyway
awk -F ',' '/^\$GPRMC/{ print $10 substr($2,1,6) "+0000" }'
# Parse said format and convert from UTC to the local time zone
date -jf '%d%m%y%H%M%S%z' '010203040506+0000' +'%a %b %d %C%y %H:%M:%S'
# The date formatting in awk (blergh)
awk -F ',' '/^\$GPRMC/{\
timestamp=$10 substr($2,1,6) "+0000" ;\
formatcommand="date -jf \"%d%m%y%H%M%S%z\" \""timestamp"\" +\"%a %b %d %C%y %H:%M:%S\"";\
formatcommand | getline formatteddate;\
close(formatcommand);\
print formatteddate }'
# The coordinate formatting in awk
awk -F ',' '/^\$GPRMC/{\
lat_degrees=substr($4,1,index($4,".")-3);\
lat_minutes=substr($4,index($4,".")-2);\
lon_degrees=substr($6,1,index($6,".")-3);\
lon_minutes=substr($6,index($6,".")-2);\
print lat_degrees "º" lat_minutes $5 "," lon_degrees "º" lon_minutes $7 }'
# Adding the other variables in output
awk -F ',' '/^\$GPRMC/{\
timestamp=$10 substr($2,1,6) "+0000" ;\
formatcommand="date -jf \"%d%m%y%H%M%S%z\" \""timestamp"\" +\"%a %b %d %C%y %H:%M:%S\"";\
formatcommand | getline formatteddate;\
close(formatcommand);\
knots=$8;\
kmh=$8 * 1.852;
lat_degrees=substr($4,1,index($4,".")-3);\
lat_minutes=substr($4,index($4,".")-2);\
latitude=lat_degrees "º" lat_minutes $5;\
longitude=lon_degrees "º" lon_minutes $7;\
lon_degrees=substr($6,1,index($6,".")-3);\
lon_minutes=substr($6,index($6,".")-2);\
print formatteddate "," latitude "," longitude "," int(kmh) " km/h" }'
# Column formatting of CSV
column -t -s,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment