summaryrefslogtreecommitdiff
path: root/gpx-to-tsv
blob: 22e6627b935a8b547f0e1e28bd7509768a4d32d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

start=$(date +%s)

sed '
  s/>/\0\n/g
  s/</\n\0/g
' \
| grep -vxF '' \
| sed -n '
  /^<gpx[[:space:]>]/,/^<\/gpx>$/ {
    /^<gpx[[:space:]>]/ d
    /^<\/gpx>$/ d
    p
  }
' \
| tr -d '\n' \
| sed '
  s@<trkpt @\n\0@g
  s@</trkpt>@\0\n@g
' \
| grep -vxF '' \
| sed '
  1 {
    \@^<metadata>.*</metadata><trk>.*<trkseg>$@ d
  }
  s@^<trkpt lat="\([-0-9.]\+\)" lon="\([-0-9.]\+\)"><ele>\([-0-9.]\+\)</ele><time>\([0-9]\{4\}\(-[0-9]\{2\}\)\{2\}T[0-9]\{2\}\(:[0-9]\{2\}\)\{2\}Z\)</time></trkpt>$@\1\t\2\t\3\t\4@
  t
  \@^</trkseg><trkseg>$@ d
  \@^</trkseg></trk>$@ d
  w /dev/stderr
' \
| while read -r lat lon ele time; do
  printf '%s\t' "${lat}" "${lon}" "${ele}"
  date -d"${time}" +%s
done

echo $(($(date +%s)-start))