diff options
-rwxr-xr-x | scripts/match-road.sh | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/scripts/match-road.sh b/scripts/match-road.sh index 6c2f242..7b6dad4 100755 --- a/scripts/match-road.sh +++ b/scripts/match-road.sh | |||
@@ -74,27 +74,20 @@ function get_valid_data() { | |||
74 | if head -1 $MATCHED| grep -F $point; then | 74 | if head -1 $MATCHED| grep -F $point; then |
75 | sed -i 1d $MATCHED | 75 | sed -i 1d $MATCHED |
76 | else | 76 | else |
77 | echo $point | 77 | echo $point -1 |
78 | fi | 78 | fi |
79 | done | 79 | done |
80 | } | 80 | } |
81 | 81 | ||
82 | get_data $1 > $ORIGIN_DATA | 82 | # Put existing timestamps to matched points, and interpolate new timestamps into new points |
83 | 83 | function complete_data() { | |
84 | # Consume raw data with serveral request | ||
85 | while [ -s $ORIGIN_DATA ]; do | ||
86 | |||
87 | head -$LIMIT $ORIGIN_DATA | make_geojson | query_matched_road | get_valid_data | ||
88 | exit 0 | ||
89 | # Put existing timestamps to matched points, and interpolate new timestamps into new points | ||
90 | while read coor index; do | 84 | while read coor index; do |
91 | if [ $index -gt -1 ]; then | 85 | if [ $index -gt -1 ]; then |
92 | echo $coor $(sed -n "$index p" $ORIGIN_DATA | cut -d' ' -f2 | date -f - +%s) | 86 | echo $coor $(sed -n "$index p" $ORIGIN_DATA | cut -d' ' -f2 | date -f - +%s) |
93 | else | 87 | else |
94 | echo $coor $index | 88 | echo $coor $index |
95 | fi | 89 | fi |
96 | done | 90 | done|\ |
97 | exit 0 | ||
98 | # interpolate timestamps to newly added points | 91 | # interpolate timestamps to newly added points |
99 | 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)}}}' |\ | 92 | 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)}}}' |\ |
100 | while read coor unix_time; do | 93 | while read coor unix_time; do |
@@ -103,13 +96,13 @@ while [ -s $ORIGIN_DATA ]; do | |||
103 | # Into [121.018088,14.5516] 1970-01-01T08:00:18.50Z | 96 | # Into [121.018088,14.5516] 1970-01-01T08:00:18.50Z |
104 | echo $coor $(date -d @$unix_time +'%Y-%m-%dT%H:%M:%S.%2NZ') | 97 | echo $coor $(date -d @$unix_time +'%Y-%m-%dT%H:%M:%S.%2NZ') |
105 | done | 98 | done |
99 | } | ||
106 | 100 | ||
107 | # Remove processed raw data | ||
108 | sed -i "1,$LIMIT d" $ORIGIN_DATA | ||
109 | done #|\ | ||
110 | # Make GPX format for output | 101 | # Make GPX format for output |
111 | sed -E 's/\[([^,]+),([^,]+)\] (.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\ | 102 | # Take input with format: [lon,lat] [time] |
112 | sed "1i \ | 103 | function make_gpx() { |
104 | sed -E 's/\[([^,]+),([^,]+)\] (.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\ | ||
105 | sed "1i \ | ||
113 | <gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ | 106 | <gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ |
114 | 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\ | 107 | 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\ |
115 | xmlns=\"http://www.topografix.com/GPX/1/1\"\n\ | 108 | xmlns=\"http://www.topografix.com/GPX/1/1\"\n\ |
@@ -118,8 +111,24 @@ sed "1i \ | |||
118 | <trk>\n\ | 111 | <trk>\n\ |
119 | <name>$(sed -nE 's/.*<name>(.*)<\/name>.*/\1/p; /<name>/q' $1)<\/name>\n\ | 112 | <name>$(sed -nE 's/.*<name>(.*)<\/name>.*/\1/p; /<name>/q' $1)<\/name>\n\ |
120 | <trkseg> | 113 | <trkseg> |
121 | \$a \ | 114 | \$a \ |
122 | \ \ \ \ <\/trkseg>\n\ | 115 | \ \ \ \ <\/trkseg>\n\ |
123 | <\/trk>\n\ | 116 | <\/trk>\n\ |
124 | <\/gpx>\n\ | 117 | <\/gpx>\n\ |
125 | " | 118 | " |
119 | } | ||
120 | |||
121 | get_data $1 > $ORIGIN_DATA | ||
122 | |||
123 | # Consume raw data with serveral request | ||
124 | while [ -s $ORIGIN_DATA ]; do | ||
125 | |||
126 | head -$LIMIT $ORIGIN_DATA |\ # Take original data by limited points at a time: [121.0179739,14.5515336] 1984-01-01T08:00:46 | ||
127 | make_geojson |\ # Make geojson body: {type: "Feature", properties: {coordTimes: [...]}, geometry: {type: "LineString", coordinates: [...]}} | ||
128 | query_matched_road |\ # Call Mapbox Map Matching API: {geometry: {coordinates: [...]}, properties: {confidence: 0.9, matching: [...], indices: [...]}} | ||
129 | get_valid_data |\ # Get valid point and index by confidence value: [121.0179739,14.5515336] 5 | ||
130 | complete_data | ||
131 | |||
132 | # Remove processed raw data | ||
133 | sed -i "1,$LIMIT d" $ORIGIN_DATA | ||
134 | done | ||