diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/match-road.sh | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/scripts/match-road.sh b/scripts/match-road.sh index 1f613b2..2cd416f 100755 --- a/scripts/match-road.sh +++ b/scripts/match-road.sh | |||
@@ -77,8 +77,7 @@ function validate_matched_points() { | |||
77 | echo $VALID_DATA | jq -c '.geometry.coordinates[]' | | 77 | echo $VALID_DATA | jq -c '.geometry.coordinates[]' | |
78 | while read point; do | 78 | while read point; do |
79 | if [[ ${point:0:1} != '[' ]]; then | 79 | if [[ ${point:0:1} != '[' ]]; then |
80 | echo -n abandoned data: > /dev/tty | 80 | echo $(sed -n "$point p" $ORIGIN_DATA) | while read coor time; do echo $coor $(date -d $time +%s); done |
81 | echo $(sed -n "$point p" $ORIGIN_DATA) | tee /dev/tty | ||
82 | sed -i 1d $MATCHED | 81 | sed -i 1d $MATCHED |
83 | elif head -1 $MATCHED | grep -F $point > /dev/null; then | 82 | elif head -1 $MATCHED | grep -F $point > /dev/null; then |
84 | index=$(head -1 $MATCHED | cut -d' ' -f2) | 83 | index=$(head -1 $MATCHED | cut -d' ' -f2) |
@@ -105,7 +104,7 @@ function complete_data() { | |||
105 | # Make GPX format for output | 104 | # Make GPX format for output |
106 | # Take input with format: [lon,lat] [time] | 105 | # Take input with format: [lon,lat] [time] |
107 | function make_gpx() { | 106 | function make_gpx() { |
108 | 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>/' |\ |
109 | sed "1i \ | 108 | sed "1i \ |
110 | <gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ | 109 | <gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ |
111 | 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\ | 110 | 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\ |
@@ -124,8 +123,8 @@ function make_gpx() { | |||
124 | 123 | ||
125 | get_data $1 > $ORIGIN_DATA | 124 | get_data $1 > $ORIGIN_DATA |
126 | 125 | ||
127 | RAW_REQUEST=$(basename $1 | tr '.' '_')_request.geojson | 126 | #RAW_REQUEST=$(basename $1 | tr '.' '_')_request.geojson |
128 | cat $ORIGIN_DATA | make_geojson | jq '.properties.stroke="#ff0000"' > $RAW_REQUEST | 127 | #cat $ORIGIN_DATA | make_geojson | jq '.properties.stroke="#ff0000"' > $RAW_REQUEST |
129 | 128 | ||
130 | # Consume raw data with serveral request | 129 | # Consume raw data with serveral request |
131 | while [ -s $ORIGIN_DATA ]; do | 130 | while [ -s $ORIGIN_DATA ]; do |
@@ -138,17 +137,33 @@ while [ -s $ORIGIN_DATA ]; do | |||
138 | make_geojson | | 137 | make_geojson | |
139 | query_matched_points | | 138 | query_matched_points | |
140 | tee -a $RESPONSES | | 139 | tee -a $RESPONSES | |
141 | validate_matched_points | 140 | validate_matched_points | |
141 | complete_data | ||
142 | 142 | ||
143 | # Remove processed raw data | 143 | # Remove processed raw data |
144 | sed -i "1,$LIMIT d" $ORIGIN_DATA | 144 | sed -i "1,$LIMIT d" $ORIGIN_DATA |
145 | done | | 145 | done |\ |
146 | make_geojson > test.geojson | 146 | sed -E 's/\[([^,]+),([^,]+)\] (.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\ |
147 | 147 | sed "1i \ | |
148 | RAW_RESPONSE=$(basename $1 | tr '.' '_')_response.geojson | 148 | <gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ |
149 | MATCHED_POINTS=$(basename $1 | tr '.' '_')_matched.geojson | 149 | 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\ |
150 | jq . $RESPONSES | jq -s '.[0].features=[.[]|.features[]] | .[0] | del(.code) | .features=(.features|map(.properties.stroke="#00ff00"))' > $RAW_RESPONSE | 150 | xmlns=\"http://www.topografix.com/GPX/1/1\"\n\ |
151 | jq ".features=(.features|map(select(.properties.confidence>=$THRESHOLD).geometry.coordinates=.properties.matchedPoints)|map(.properties.stroke=\"#0000ff\"))" $RAW_RESPONSE > $MATCHED_POINTS | 151 | xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v1\"\n\ |
152 | xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n\ | ||
153 | <trk>\n\ | ||
154 | <name>$(sed -nE 's/.*<name>(.*)<\/name>.*/\1/p; /<name>/q' $1)<\/name>\n\ | ||
155 | <trkseg> | ||
156 | \$a \ | ||
157 | \ \ \ \ <\/trkseg>\n\ | ||
158 | <\/trk>\n\ | ||
159 | <\/gpx>\n\ | ||
160 | " | ||
161 | #make_geojson > test.geojson | ||
152 | 162 | ||
153 | DEBUG=$(basename $1 | tr '.' '_')_total.geojson | 163 | #RAW_RESPONSE=$(basename $1 | tr '.' '_')_response.geojson |
154 | cat $RAW_REQUEST $RAW_RESPONSE $MATCHED_POINTS | jq -s '{type: "FeatureCollection", features: ([.[0]] + .[1].features + .[2].features)}' > $DEBUG | 164 | #MATCHED_POINTS=$(basename $1 | tr '.' '_')_matched.geojson |
165 | #jq . $RESPONSES | jq -s '.[0].features=[.[]|.features[]] | .[0] | del(.code) | .features=(.features|map(.properties.stroke="#00ff00"))' > $RAW_RESPONSE | ||
166 | #jq ".features=(.features|map(select(.properties.confidence>=$THRESHOLD).geometry.coordinates=.properties.matchedPoints)|map(.properties.stroke=\"#0000ff\"))" $RAW_RESPONSE > $MATCHED_POINTS | ||
167 | # | ||
168 | #DEBUG=$(basename $1 | tr '.' '_')_total.geojson | ||
169 | #cat $RAW_REQUEST $RAW_RESPONSE $MATCHED_POINTS | jq -s '{type: "FeatureCollection", features: ([.[0]] + .[1].features + .[2].features)}' > $DEBUG | ||