diff options
Diffstat (limited to 'scripts/match.sh')
-rwxr-xr-x | scripts/match.sh | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/scripts/match.sh b/scripts/match.sh index 876b78d..e76ddec 100755 --- a/scripts/match.sh +++ b/scripts/match.sh | |||
@@ -14,8 +14,7 @@ paste -d' ' \ | |||
14 | <(sed -nr 's/.*lon=\"([^\"]+)\".*/\1/p' $1) \ | 14 | <(sed -nr 's/.*lon=\"([^\"]+)\".*/\1/p' $1) \ |
15 | <(sed -nr 's/.*lat=\"([^\"]+)\".*/\1/p' $1) |\ | 15 | <(sed -nr 's/.*lat=\"([^\"]+)\".*/\1/p' $1) |\ |
16 | sed -r 's/ ([^ ]+) ([^ ]+)/ [\1,\2]/' |\ | 16 | sed -r 's/ ([^ ]+) ([^ ]+)/ [\1,\2]/' |\ |
17 | awk '!_[$1]++' |\ | 17 | awk '!_[$1]++' > origin |
18 | awk '!_[$2]++' > origin | ||
19 | 18 | ||
20 | while [ -s origin ] | 19 | while [ -s origin ] |
21 | do | 20 | do |
@@ -24,19 +23,22 @@ do | |||
24 | <(head -$LIMIT origin | cut -d' ' -f1 | jq -nR '[inputs]') |\ | 23 | <(head -$LIMIT origin | cut -d' ' -f1 | jq -nR '[inputs]') |\ |
25 | curl -X POST -s --header "Content-Type:application/json" --data @- https://api.mapbox.com/matching/v4/mapbox.driving.json?access_token=$ACCESS_TOKEN > response | 24 | curl -X POST -s --header "Content-Type:application/json" --data @- https://api.mapbox.com/matching/v4/mapbox.driving.json?access_token=$ACCESS_TOKEN > response |
26 | 25 | ||
26 | TIMESTAMP=0 | ||
27 | paste -d' ' \ | ||
28 | <(jq -c '.features[0].properties.matchedPoints[]' response) \ | ||
29 | <(jq -c '.features[0].properties.indices[]' response | xargs -I{} echo {}+1 | bc | xargs -I{} sed -n {}p origin | cut -d' ' -f1 | date -f - +%s) \ | ||
30 | > matched | ||
27 | jq -c '.features[0].geometry.coordinates[]' response |\ | 31 | jq -c '.features[0].geometry.coordinates[]' response |\ |
28 | while read line | 32 | while read line |
29 | do | 33 | do |
30 | paste -d' ' \ | 34 | TIMESTAMP=$(head -1 matched | cut -d' ' -f2) |
31 | <(jq -c '.features[0].properties.matchedPoints[]' response) \ | 35 | (head -1 matched | grep -F $line && sed -i 1d matched) || echo $line $TIMESTAMP jojo |
32 | <(jq -c '.features[0].properties.indices[]' response | xargs -I{} echo {}+1 | bc | xargs -I{} sed -n {}p origin | cut -d' ' -f1 | date -f - +%s) |\ | ||
33 | grep -F $line | head -1 || echo $line | ||
34 | done |\ | 36 | done |\ |
35 | tee /dev/tty | 37 | tee /dev/tty && rm matched |
36 | 38 | ||
37 | sed -i "1,$LIMIT d" origin | 39 | sed -i "1,$LIMIT d" origin |
38 | done |\ | 40 | done |\ |
39 | sed -r 's/\[([^,]+),([^,]+)\] (.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\ | 41 | sed -r 's/\[([^,]+),([^,]+)\] ?(.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\ |
40 | sed "1i \ | 42 | sed "1i \ |
41 | <gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ | 43 | <gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ |
42 | xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd\"\n\ | 44 | xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd\"\n\ |
@@ -50,5 +52,4 @@ sed "1i \ | |||
50 | \ \ \ \ <\/trkseg>\n\ | 52 | \ \ \ \ <\/trkseg>\n\ |
51 | <\/trk>\n\ | 53 | <\/trk>\n\ |
52 | <\/gpx>\n\ | 54 | <\/gpx>\n\ |
53 | " |\ | 55 | " | tee output.gpx |
54 | tee output.gpx | ||