diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/match.sh | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/scripts/match.sh b/scripts/match.sh index f48f0a2..3c1216a 100755 --- a/scripts/match.sh +++ b/scripts/match.sh | |||
@@ -1,42 +1,54 @@ | |||
1 | #! /bin/bash | 1 | #! /bin/bash |
2 | 2 | ||
3 | set -x | 3 | #set -x |
4 | 4 | ||
5 | ACCESS_TOKEN=$(cat ~/settings/tokens/mapbox) | 5 | ACCESS_TOKEN=$(cat ~/settings/tokens/mapbox) |
6 | export MAPBOX_ACCESS_TOKEN=$ACCESS_TOKEN | 6 | #export MAPBOX_ACCESS_TOKEN=$ACCESS_TOKEN |
7 | LIMIT=10 | 7 | LIMIT=100 |
8 | TRK_NAME=$(sed -nr 's/.*<name>(.*)<\/name>.*/\1/p; /<name>/q' $1) | ||
8 | 9 | ||
10 | # Need to add pre-process for duplicated gpx trkpts | ||
9 | paste -d' ' \ | 11 | paste -d' ' \ |
10 | <(sed -nr '/<trk>/,/<\/trk>/ { s/.*<time>(.*)<\/time>/\1/p }' $1) \ | 12 | <(sed -nr '/<trk>/,/<\/trk>/ { s/.*<time>(.*)<\/time>/\1/p }' $1 | cut -d'.' -f1) \ |
11 | <(sed -nr 's/.*lon=\"([^\"]+)\" lat=\"([^\"]+)\".*/[\1,\2]/p' $1) \ | 13 | <(sed -nr 's/.*lon=\"([^\"]+)\".*/\1/p' $1) \ |
12 | > origin | 14 | <(sed -nr 's/.*lat=\"([^\"]+)\".*/\1/p' $1) |\ |
13 | 15 | sed -r 's/ ([^ ]+) ([^ ]+)/ [\1,\2]/' |\ | |
14 | while true | 16 | awk '!_[$1]++' |\ |
17 | awk '!_[$2]++' > origin | ||
18 | |||
19 | while [ -s origin ] | ||
15 | do | 20 | do |
16 | jq --slurp '{type: "Feature", properties: {coordTimes: .[1]}, geometry: {type: "LineString", coordinates: .[0]}}' \ | 21 | jq --slurp '{type: "Feature", properties: {coordTimes: .[1]}, geometry: {type: "LineString", coordinates: .[0]}}' \ |
17 | <(head -$LIMIT origin | cut -d' ' -f2 | jq -n '[inputs]') \ | 22 | <(head -$LIMIT origin | cut -d' ' -f2 | jq -n '[inputs]') \ |
18 | <(head -$LIMIT origin | cut -d' ' -f1 | jq -nR '[inputs]') |\ | 23 | <(head -$LIMIT origin | cut -d' ' -f1 | jq -nR '[inputs]') |\ |
19 | mapbox mapmatching --profile mapbox.driving - > response | 24 | tee input.geojson |\ |
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 | ||
20 | 26 | ||
21 | jq -c '.features[0].geometry.coordinates[]' response |\ | 27 | jq -c '.features[0].geometry.coordinates[]' response |\ |
22 | while read line | 28 | while read line |
23 | do | 29 | do |
24 | paste -d' ' \ | 30 | paste -d' ' \ |
25 | <(jq -c '.features[0].properties.matchedPoints[]' response) \ | 31 | <(jq -c '.features[0].properties.matchedPoints[]' response) \ |
26 | <(jq -c '.features[0].properties.indices[]' response | xargs -I{} echo {}+1 | bc | tee /dev/tty | xargs -I{} sed -n {}p origin | cut -d' ' -f1) |\ | 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) |\ |
27 | grep -F $line || echo $line | 33 | grep -F $line | head -1 || echo $line |
28 | done | 34 | done |\ |
35 | tee /dev/tty | ||
29 | 36 | ||
30 | sed -i "1,$LIMIT d" origin | 37 | sed -i "1,$LIMIT d" origin |
31 | if [ ! -s origin ]; then exit 0; fi | 38 | done |\ |
32 | done | 39 | sed -r 's/\[([^,]+),([^,]+)\] (.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\ |
33 | 40 | sed "1i \ | |
34 | #sed -nr 's/.*lon=\"([^\"]+)\" lat=\"([^\"]+)\".*/\1,\2/p' $1 |\ | 41 | <gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ |
35 | #xargs -L100 echo -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\ |
36 | #echo jojo | 43 | xmlns=\"http://www.topografix.com/GPX/1/1\"\n\ |
37 | #tr ' ' ';' |\ | 44 | xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v1\"\n\ |
38 | #sed 's/^/coordinates=/' |\ | 45 | xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n\ |
39 | #curl -X POST \ | 46 | <trk>\n\ |
40 | # --data @- \ | 47 | <name>$TRK_NAME<\/name>\n\ |
41 | # https://api.mapbox.com/matching/v4/mapbox/driving?access_token=$ACCESS_TOKEN&geometries=geojson&steps=true | 48 | <trkseg> |
42 | 49 | \$a \ | |
50 | \ \ \ \ <\/trkseg>\n\ | ||
51 | <\/trk>\n\ | ||
52 | <\/gpx>\n\ | ||
53 | " |\ | ||
54 | tee output.gpx | ||