aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xscripts/match-road.sh23
1 files changed, 15 insertions, 8 deletions
diff --git a/scripts/match-road.sh b/scripts/match-road.sh
index f7d27cc..853980a 100755
--- a/scripts/match-road.sh
+++ b/scripts/match-road.sh
@@ -31,24 +31,31 @@ function get_data() {
31 sed -nr '/<trkpt /, /<\/trkpt>/ {H; /<\/trkpt>/ {x; s/\n/ /g; p; s/.*//; x}}' $1 |\ 31 sed -nr '/<trkpt /, /<\/trkpt>/ {H; /<\/trkpt>/ {x; s/\n/ /g; p; s/.*//; x}}' $1 |\
32 sed -nr 'h; s/.*lon="([^"]+).*/\1/; H; g 32 sed -nr 'h; s/.*lon="([^"]+).*/\1/; H; g
33 s/.*lat="([^"]+).*/\1/; H; g 33 s/.*lat="([^"]+).*/\1/; H; g
34 # If trkpt has no time, leave it blank
34 /time/ { 35 /time/ {
35 s/.*<time>([^.]+).*<\/time>.*/\1/ 36 s/.*<time>([^.]+).*<\/time>.*/\1/
36 H; g 37 H; g
37 } 38 }
38 s/^[^\n]+\n//; s/\n/ /g; p' |\ 39 s/^[^\n]+\n//; s/\n/ /g; p' |\
40 sed -r 's/^([^ ]+) ([^ ]+)/[\1,\2]/' |\
39 awk '!_[$2]++' 41 awk '!_[$2]++'
40} 42}
41 43
42get_data $1 # > $ORIGIN_DATA 44# Read date Make GeoJSON object for Map Matching API
43exit 0 45function make_geojson() {
46 jq --slurp '{type: "Feature", properties: {coordTimes: .[1]}, geometry: {type: "LineString", coordinates: .[0]}}' \
47 <(cut -d' ' -f1 | jq -n '[inputs]') \
48 <(cut -d' ' -f2 | jq -nR '[inputs]') |\
49 tee tmp_$(head -1 $ORIGIN_DATA | cut -d ' ' -f2 | date -f - +%s).geojson
50}
51
52get_data $1 | tee /dev/tty > $ORIGIN_DATA
44 53
45# Consume raw data with serveral request 54# Consume raw data with serveral request
46while [ -s $ORIGIN_DATA ]; do 55while [ -s $ORIGIN_DATA ]; do
47 # Make GeoJSON object for request 56 head -$LIMIT $ORIGIN_DATA |\
48 jq --slurp '{type: "Feature", properties: {coordTimes: .[1]}, geometry: {type: "LineString", coordinates: .[0]}}' \ 57 make_geojson
49 <(head -$LIMIT $ORIGIN_DATA | cut -d' ' -f2 | jq -n '[inputs]') \ 58 exit 0
50 <(head -$LIMIT $ORIGIN_DATA | cut -d' ' -f1 | jq -nR '[inputs]') |\
51 tee tmp_$(head -1 $ORIGIN_DATA | cut -d ' ' -f1 | date -f - +%s).geojson |\
52 # Mapbox Map Matching API, store response into tmp file 59 # Mapbox Map Matching API, store response into tmp file
53 curl -X POST -s --data @- --header "Content-Type:application/json" https://api.mapbox.com/matching/v4/mapbox.driving.json?access_token=$ACCESS_TOKEN > $RESPONSE 60 curl -X POST -s --data @- --header "Content-Type:application/json" https://api.mapbox.com/matching/v4/mapbox.driving.json?access_token=$ACCESS_TOKEN > $RESPONSE
54 61
@@ -74,7 +81,7 @@ while [ -s $ORIGIN_DATA ]; do
74 81
75 # Remove processed raw data 82 # Remove processed raw data
76 sed -i "1,$LIMIT d" $ORIGIN_DATA 83 sed -i "1,$LIMIT d" $ORIGIN_DATA
77done |\ 84done #|\
78# Make GPX format for output 85# Make GPX format for output
79sed -E 's/\[([^,]+),([^,]+)\] (.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\ 86sed -E 's/\[([^,]+),([^,]+)\] (.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\
80sed "1i \ 87sed "1i \