Last active
July 31, 2022 00:23
-
-
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
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
#!/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>\ | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment