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/csv.move_column | 18 ----- tools/csv.reorder | 17 ----- tools/csv/csv.move_column | 18 +++++ tools/csv/csv.reorder | 17 +++++ tools/csv/csv2geojson | 46 ++++++++++++ tools/csv2geojson | 46 ------------ tools/gis/match-road.sh | 148 +++++++++++++++++++++++++++++++++++++++ tools/git/swap-protocol.bash | 25 +++++++ tools/github-release.sh | 154 ----------------------------------------- tools/github/github-release.sh | 154 +++++++++++++++++++++++++++++++++++++++++ tools/match-road.sh | 148 --------------------------------------- tools/swap-protocol.bash | 25 ------- 12 files changed, 408 insertions(+), 408 deletions(-) delete mode 100755 tools/csv.move_column delete mode 100755 tools/csv.reorder create mode 100755 tools/csv/csv.move_column create mode 100755 tools/csv/csv.reorder create mode 100755 tools/csv/csv2geojson delete mode 100755 tools/csv2geojson create mode 100755 tools/gis/match-road.sh create mode 100755 tools/git/swap-protocol.bash delete mode 100755 tools/github-release.sh create mode 100755 tools/github/github-release.sh delete mode 100755 tools/match-road.sh delete mode 100755 tools/swap-protocol.bash (limited to 'tools') diff --git a/tools/csv.move_column b/tools/csv.move_column deleted file mode 100755 index a62701f..0000000 --- a/tools/csv.move_column +++ /dev/null @@ -1,18 +0,0 @@ -#! /bin/bash - -# show each field with index in csv -echo -------------- > /dev/tty -head -1 < $1 | sed 's/,/ /g' | awk '{for (i=1; i<=NF; i++) printf $i "_" i " "; print ""}' > /dev/tty -echo -------------- > /dev/tty -echo > /dev/tty - -# get index of lon/lat column -read -p "Move which column? " origin_col -read -p "To which index? " new_col - -cat $1 | -# move lon and lat to the first and second column -awk -F',' -v OFS="," -v origin_th=$origin_col -v new_th=$new_col '\ - {for (i=1; i<= NF; i++) if (i == new_th) printf $origin_th OFS $i OFS; else if (i == origin_th); else printf $i OFS; print ""}\ - ' |\ -sed 's/,$//g' diff --git a/tools/csv.reorder b/tools/csv.reorder deleted file mode 100755 index 8a64239..0000000 --- a/tools/csv.reorder +++ /dev/null @@ -1,17 +0,0 @@ -#! /bin/bash - -# show each field with index in csv -echo -------------- > /dev/tty -head -1 < $1 | awk -F',' '{for (i=1; i<=NF; i++) printf $i "_" i " "; print ""}' > /dev/tty -echo -------------- > /dev/tty -echo > /dev/tty - -read -p "type column numbers by new order, like 3 2 1: " order - -arrange=$(echo $order | sed -r 's/([^ ]+)/$\1/g' | tr ' ' ',') - -cat $1 |\ -awk -F',' "BEGIN{OFS=\",\"}{print $arrange}" |\ -tee /tmp/csv - -echo "Also copied to /tmp/csv" > /dev/tty diff --git a/tools/csv/csv.move_column b/tools/csv/csv.move_column new file mode 100755 index 0000000..a62701f --- /dev/null +++ b/tools/csv/csv.move_column @@ -0,0 +1,18 @@ +#! /bin/bash + +# show each field with index in csv +echo -------------- > /dev/tty +head -1 < $1 | sed 's/,/ /g' | awk '{for (i=1; i<=NF; i++) printf $i "_" i " "; print ""}' > /dev/tty +echo -------------- > /dev/tty +echo > /dev/tty + +# get index of lon/lat column +read -p "Move which column? " origin_col +read -p "To which index? " new_col + +cat $1 | +# move lon and lat to the first and second column +awk -F',' -v OFS="," -v origin_th=$origin_col -v new_th=$new_col '\ + {for (i=1; i<= NF; i++) if (i == new_th) printf $origin_th OFS $i OFS; else if (i == origin_th); else printf $i OFS; print ""}\ + ' |\ +sed 's/,$//g' diff --git a/tools/csv/csv.reorder b/tools/csv/csv.reorder new file mode 100755 index 0000000..8a64239 --- /dev/null +++ b/tools/csv/csv.reorder @@ -0,0 +1,17 @@ +#! /bin/bash + +# show each field with index in csv +echo -------------- > /dev/tty +head -1 < $1 | awk -F',' '{for (i=1; i<=NF; i++) printf $i "_" i " "; print ""}' > /dev/tty +echo -------------- > /dev/tty +echo > /dev/tty + +read -p "type column numbers by new order, like 3 2 1: " order + +arrange=$(echo $order | sed -r 's/([^ ]+)/$\1/g' | tr ' ' ',') + +cat $1 |\ +awk -F',' "BEGIN{OFS=\",\"}{print $arrange}" |\ +tee /tmp/csv + +echo "Also copied to /tmp/csv" > /dev/tty diff --git a/tools/csv/csv2geojson b/tools/csv/csv2geojson new file mode 100755 index 0000000..e742be6 --- /dev/null +++ b/tools/csv/csv2geojson @@ -0,0 +1,46 @@ +#! /bin/bash + +# -s to skip specify columns of longitude and latitude +for i in "$@" +do +case $i in + -s) + lon_col=0; lat_col=1 + shift;; + + *) + csv=$i + shift;; +esac +done + +# if no -s option, just read from input +if [ "$lon_col" != "0" ]; then + # show each field with index in csv + echo -------------- > /dev/tty + head -1 < $csv | tr ',' '\n' | nl > /dev/tty + echo -------------- > /dev/tty + echo > /dev/tty + + # get index of lon/lat column + read -p "Number of longitude column: " lon_col + read -p "Number of latitude column: " lat_col +fi + +(which dos2unix &>/dev/null && dos2unix <$csv || cat $csv) |\ +# move lon and lat to the first and second column +awk -F',' -v lon_th=$lon_col -v lat_th=$lat_col '\ + BEGIN{OFS=","}\ + {printf $lon_th "," $lat_th; for (i=1; i<= NF; i++) if (i != lat_th && i != lon_th) printf "," $i; print ""}\ + ' |\ +# change csv into array format, like [lon, lat, "field1", field2...] +sed 's/[^,]*/"\0"/g; s/.*/[\0]/g' |\ +# wrap other fields as a json object, like [lon, lat, {...}] +jq -s '.[0][2:] as $fields | .[1:][] | [.[0], .[1], ([$fields, .[2:]] | transpose | map({(.[0]): .[1]}) | add)]' |\ +# create array of geojson point features +jq '{"type": "Feature", "properties": .[2], "geometry":{ "type": "Point", "coordinates": [(.[0] | tonumber), (.[1] | tonumber)] } }' |\ +# wrap features as geojson format +jq -s '{"type": "FeatureCollection", "features": .}' |\ +tee /tmp/geojson + +echo stored into /tmp/geojson > /dev/tty diff --git a/tools/csv2geojson b/tools/csv2geojson deleted file mode 100755 index e742be6..0000000 --- a/tools/csv2geojson +++ /dev/null @@ -1,46 +0,0 @@ -#! /bin/bash - -# -s to skip specify columns of longitude and latitude -for i in "$@" -do -case $i in - -s) - lon_col=0; lat_col=1 - shift;; - - *) - csv=$i - shift;; -esac -done - -# if no -s option, just read from input -if [ "$lon_col" != "0" ]; then - # show each field with index in csv - echo -------------- > /dev/tty - head -1 < $csv | tr ',' '\n' | nl > /dev/tty - echo -------------- > /dev/tty - echo > /dev/tty - - # get index of lon/lat column - read -p "Number of longitude column: " lon_col - read -p "Number of latitude column: " lat_col -fi - -(which dos2unix &>/dev/null && dos2unix <$csv || cat $csv) |\ -# move lon and lat to the first and second column -awk -F',' -v lon_th=$lon_col -v lat_th=$lat_col '\ - BEGIN{OFS=","}\ - {printf $lon_th "," $lat_th; for (i=1; i<= NF; i++) if (i != lat_th && i != lon_th) printf "," $i; print ""}\ - ' |\ -# change csv into array format, like [lon, lat, "field1", field2...] -sed 's/[^,]*/"\0"/g; s/.*/[\0]/g' |\ -# wrap other fields as a json object, like [lon, lat, {...}] -jq -s '.[0][2:] as $fields | .[1:][] | [.[0], .[1], ([$fields, .[2:]] | transpose | map({(.[0]): .[1]}) | add)]' |\ -# create array of geojson point features -jq '{"type": "Feature", "properties": .[2], "geometry":{ "type": "Point", "coordinates": [(.[0] | tonumber), (.[1] | tonumber)] } }' |\ -# wrap features as geojson format -jq -s '{"type": "FeatureCollection", "features": .}' |\ -tee /tmp/geojson - -echo stored into /tmp/geojson > /dev/tty 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/.*