diff options
author | Markus Koch <markus@notsyncing.net> | 2021-03-13 18:49:23 +0100 |
---|---|---|
committer | Markus Koch <markus@notsyncing.net> | 2021-03-13 18:49:23 +0100 |
commit | 6cc5cb8b4b600a6262f1d51e08ea40c6124efc72 (patch) | |
tree | 18dfaacb96f6dff1078a84ccbfbe1d4a596297f3 /scripts/geojson/maps/fetch_trainlines.sh | |
parent | 034bef5e2a8e54b6cb01afef574e811cf4e06d4d (diff) | |
download | lifomapserver-6cc5cb8b4b600a6262f1d51e08ea40c6124efc72.tar.gz lifomapserver-6cc5cb8b4b600a6262f1d51e08ea40c6124efc72.tar.bz2 lifomapserver-6cc5cb8b4b600a6262f1d51e08ea40c6124efc72.zip |
scripts: Add fetch_trainlines.sh
Diffstat (limited to 'scripts/geojson/maps/fetch_trainlines.sh')
-rwxr-xr-x | scripts/geojson/maps/fetch_trainlines.sh | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/geojson/maps/fetch_trainlines.sh b/scripts/geojson/maps/fetch_trainlines.sh new file mode 100755 index 0000000..f0c4d25 --- /dev/null +++ b/scripts/geojson/maps/fetch_trainlines.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Maps:Trainlines'` +data=`echo "$json" | json_reformat | sed -e 's/\\\\n//g' -n -e 's/begin:mapdata\([^}]\+\)/\1/gp' | sed -e "s/|-|/}/g"` + +section="" +echo "[" +export IFS="}" +for entry in $data; do + this_section=`echo $entry | sed -n 's/.*== \([^=]\+\) ==.*/\1/p'` + if [[ "$this_section" != "" ]]; then + section=$this_section + fi + + if [[ "$section" != "$1" ]]; then + continue + fi + + case "$section" in + "Train Lines") + name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'` + start=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'` + end=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\([^|]\+\)||\s*\([^|]\+\).*/\3/p' | sed 's/ $//'` + coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'` + if [[ "$name" != "" && "$coord" != "" ]]; then + echo "{ \"type\": \"Feature\", + \"geometry\": { + \"type\": \"LineString\", + \"coordinates\": [ + $coord + ] + }, + \"properties\": { + \"name\": \"$name\", + \"start\": \"$start\", + \"end\": \"$end\" + } +}," + fi + ;; + "Access Paths") + name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'` + lines=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'` + coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'` + if [[ "$type" == "district" ]]; then + continue; + fi + if [[ "$name" != "" && "$coord" != "" ]]; then + echo "{ \"type\": \"Feature\", + \"geometry\": { + \"type\": \"LineString\", + \"coordinates\": [ + $coord + ] + }, + \"properties\": { + \"name\": \"$lines:$name\" + } +}," + fi + ;; + esac +done +export IFS=" " +echo "{}" +echo "]" |