From c2c497544e005239411896632b592901e4fc475a Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Fri, 28 Aug 2020 10:19:25 +0800 Subject: update --- tools/gis/match-road.sh | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100755 tools/gis/match-road.sh (limited to 'tools/gis') diff --git a/tools/gis/match-road.sh b/tools/gis/match-road.sh new file mode 100755 index 0000000..d9beaae --- /dev/null +++ b/tools/gis/match-road.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env bash +# +# Author: Pham +# +# This script accepts a single GPX file as parameter and +# output the processed GPX body to STDOUT, using Mapbox Map Matching API v4. +# read doc at: https://docs.mapbox.com/api/legacy/map-matching-v4/ +# +# Example: +# +# match-road.sh raw.gpx > new.gpx +# +# Hint: +# +# Remember to put Mapbox Access Token at the top! + +#set -x +set -e + +# put yout Mapbox token here +ACCESS_TOKEN=$(cat ~/settings/tokens/mapbox) +# number of coordinates for each Mapbox Map Matching API request, Maximum value is 100 +LIMIT=100 +# define the lowest confidence of accepted matched points +THRESHOLD=0.0001 + +if [[ -z $1 ]]; then echo "You need to give a gpx file!"; exit 1; fi +ORIGIN_DATA=/tmp/$(basename $1).origin +RESPONSES=/tmp/$(basename $1).responses && true > $RESPONSES +MATCHED=/tmp/$(basename $1).matched + +# extract data from the given gpx file +# only keep first point and remove the rest which in the same "second" +# input: [gpx format] +# output: [121.0179739,14.5515336] 1984-01-01T08:00:46 +get_data() { + sed -nr '// {H; /<\/trkpt>/ {x; s/\n/ /g; p; s/.*//; x}}' $1 | + sed -nr 'h; s/.*lon="([^"]+).*/\1/; H; g + s/.*lat="([^"]+).*/\1/; H; g + # If trkpt has no time, leave it blank + /time/ { + s/.*