#!/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 ACCESS_TOKEN=$(cat ~/settings/tokens/mapbox) # put yout Mapbox token here LIMIT=10 # number of coordinates for each Mapbox Map Matching API request, Maximum value is 100 ORIGIN_DATA=/tmp/origin RESPONSE=/tmp/response # extract data from the given gpx file, dump coordindate and time with the following format: # [121.0179739,14.5515336] 1984-01-01T08:00:46.234 function get_data() { paste -d' ' \ <(sed -nE '// s/.*lon=\"([^\"]+).*/\1/p' $1) \ <(sed -nE '// s/.*lat=\"([^\"]+).*/\1/p' $1) \ <(sed -nE '// s/.*