#!/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/.*