Skip to content

Instantly share code, notes, and snippets.

@typebrook
Last active July 31, 2022 00:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typebrook/b8350899206c17023c59589f4b3a15d2 to your computer and use it in GitHub Desktop.
Save typebrook/b8350899206c17023c59589f4b3a15d2 to your computer and use it in GitHub Desktop.
[geojson-script] Transform geojson from GoPro video to gpx format, jq needed #geojson #gpx #garmin
#!/bin/bash
paste <(jq '.geometry.coordinates[]' $1 -c | sed -r 's/\[|\]//g' \
|sed -r 's/^([^,]+),([^,]+),.*/<trkpt lat="\2" lon="\1">/') \
<(jq '.properties.AbsoluteUtcMicroSec[]' $1 \
| sed -r 's/(.*)(.{3})$$/\1,\2/' \
| xargs -I time date -d @time +"%Y-%m-%dT%H:%M:%S") |\
# If you want to keep points at the same seconds, comment out the next line
uniq -f3 |\
sed -r 's/\t(.*)/<time>\1<\/time><\/trkpt>/' |\
sed '1i \
<?xml version="1.0" encoding="utf8"?>\
<gpx xmlns=\"http:\/\/www.topografix.com\/GPX\/1\/1\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:gpxtpx=\"http:\/\/www.garmin.com\/xmlschemas\/TrackPointExtension\/v2\" xsi:schemaLocation=\"http:\/\/www.topografix.com\/GPX\/1\/1 http:\/\/www.topografix.com\/GPX\/1\/1\/gpx.xsd\">\
<trk>\
<name>$layer<\/name>\
<trkseg>
$a \
<\/trkseg>\
<\/trk>\
<\/gpx>\
'
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment