diff options
author | typebrook <typebrook@gmail.com> | 2019-12-27 14:47:05 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2019-12-27 14:47:05 +0800 |
commit | 4c5cc9aa1dbe4799a08cb9b0c3485a7c3eef25f7 (patch) | |
tree | 1a04f0f41c0bbdff6ffff06d7d2e8b5e8e339458 /scripts | |
parent | 7c8ebbe054ecd90a7b0e764cf190658e83311ea7 (diff) |
update
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/match-road.sh | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/scripts/match-road.sh b/scripts/match-road.sh index 1c7d107..d9beaae 100755 --- a/scripts/match-road.sh +++ b/scripts/match-road.sh | |||
@@ -33,7 +33,7 @@ MATCHED=/tmp/$(basename $1).matched | |||
33 | # only keep first point and remove the rest which in the same "second" | 33 | # only keep first point and remove the rest which in the same "second" |
34 | # input: [gpx format] | 34 | # input: [gpx format] |
35 | # output: [121.0179739,14.5515336] 1984-01-01T08:00:46 | 35 | # output: [121.0179739,14.5515336] 1984-01-01T08:00:46 |
36 | function get_data() { | 36 | get_data() { |
37 | sed -nr '/<trkpt /, /<\/trkpt>/ {H; /<\/trkpt>/ {x; s/\n/ /g; p; s/.*//; x}}' $1 | | 37 | sed -nr '/<trkpt /, /<\/trkpt>/ {H; /<\/trkpt>/ {x; s/\n/ /g; p; s/.*//; x}}' $1 | |
38 | sed -nr 'h; s/.*lon="([^"]+).*/\1/; H; g | 38 | sed -nr 'h; s/.*lon="([^"]+).*/\1/; H; g |
39 | s/.*lat="([^"]+).*/\1/; H; g | 39 | s/.*lat="([^"]+).*/\1/; H; g |
@@ -50,14 +50,14 @@ function get_data() { | |||
50 | # Output GeoJSON object for Map Matching API | 50 | # Output GeoJSON object for Map Matching API |
51 | # input: [121.0179739,14.5515336] 1984-01-01T08:00:46 | 51 | # input: [121.0179739,14.5515336] 1984-01-01T08:00:46 |
52 | # output: {type: "Feature", properties: {coordTimes: [...]}, geometry: {type: "LineString", coordinates: [...]}} | 52 | # output: {type: "Feature", properties: {coordTimes: [...]}, geometry: {type: "LineString", coordinates: [...]}} |
53 | function make_geojson() { | 53 | make_geojson() { |
54 | # change input to format like: [[lon, lat], time] | 54 | # change input to format like: [[lon, lat], time] |
55 | awk '{printf("[%s,\"%s\"]\n", $1, $2)}' | | 55 | awk '{printf("[%s,\"%s\"]\n", $1, $2)}' | |
56 | jq '[inputs] | {type: "Feature", geometry: {type: "LineString", coordinates: map(.[0])}, properties: {coordTimes: (map(.[1]))}}' | 56 | jq '[inputs] | {type: "Feature", geometry: {type: "LineString", coordinates: map(.[0])}, properties: {coordTimes: (map(.[1]))}}' |
57 | } | 57 | } |
58 | 58 | ||
59 | # Read GeoJSON body from STDIN, and return result from Mapbox Map Matching API | 59 | # Read GeoJSON body from STDIN, and return result from Mapbox Map Matching API |
60 | function query_matched_points() { | 60 | query_matched_points() { |
61 | curl -X POST -s --data @- \ | 61 | curl -X POST -s --data @- \ |
62 | --header "Content-Type:application/json" \ | 62 | --header "Content-Type:application/json" \ |
63 | https://api.mapbox.com/matching/v4/mapbox.driving.json?access_token=$ACCESS_TOKEN | 63 | https://api.mapbox.com/matching/v4/mapbox.driving.json?access_token=$ACCESS_TOKEN |
@@ -68,7 +68,7 @@ function query_matched_points() { | |||
68 | # [121.0179739,14.5515336] 35 | 68 | # [121.0179739,14.5515336] 35 |
69 | # If the point is newly added, the index would be -1, like | 69 | # If the point is newly added, the index would be -1, like |
70 | # [121.0189339,14.5525931] -1 | 70 | # [121.0189339,14.5525931] -1 |
71 | function validate_matched_points() { | 71 | validate_matched_points() { |
72 | VALID_DATA=$(jq ".features[] | if(.properties.confidence < $THRESHOLD) then .geometry.coordinates=(.properties.indices|map(.+1)) else . end") | 72 | VALID_DATA=$(jq ".features[] | if(.properties.confidence < $THRESHOLD) then .geometry.coordinates=(.properties.indices|map(.+1)) else . end") |
73 | 73 | ||
74 | echo $VALID_DATA | | 74 | echo $VALID_DATA | |
@@ -90,7 +90,7 @@ function validate_matched_points() { | |||
90 | } | 90 | } |
91 | 91 | ||
92 | # Put existing timestamps to matched points, and interpolate new timestamps into new points | 92 | # Put existing timestamps to matched points, and interpolate new timestamps into new points |
93 | function complete_data() { | 93 | complete_data() { |
94 | # interpolate timestamps to newly added points | 94 | # interpolate timestamps to newly added points |
95 | awk '{COOR[NR][0]=$1; N++; COOR[NR][1]=$2} END{for (i=1; i<=N; i++) {printf COOR[i][0]; if (COOR[i][1] != -1) {print " "COOR[i][1]; LAST=i} else {while(COOR[i+n][1] == -1) n++; print " "COOR[LAST][1]+(COOR[i+n][1]-COOR[LAST][1])*(i-LAST)/(i+n-LAST)}}}' | | 95 | awk '{COOR[NR][0]=$1; N++; COOR[NR][1]=$2} END{for (i=1; i<=N; i++) {printf COOR[i][0]; if (COOR[i][1] != -1) {print " "COOR[i][1]; LAST=i} else {while(COOR[i+n][1] == -1) n++; print " "COOR[LAST][1]+(COOR[i+n][1]-COOR[LAST][1])*(i-LAST)/(i+n-LAST)}}}' | |
96 | while read coor unix_time; do | 96 | while read coor unix_time; do |
@@ -103,7 +103,7 @@ function complete_data() { | |||
103 | 103 | ||
104 | # Make GPX format for output | 104 | # Make GPX format for output |
105 | # Take input with format: [lon,lat] [time] | 105 | # Take input with format: [lon,lat] [time] |
106 | function make_gpx() { | 106 | make_gpx() { |
107 | sed -E 's/\[([^,]+),([^,]+)\] (.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' | | 107 | sed -E 's/\[([^,]+),([^,]+)\] (.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' | |
108 | sed "1i \ | 108 | sed "1i \ |
109 | <gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ | 109 | <gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ |