From 6a779db77b5983afd955efa6456655c106b8cbaf Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sat, 25 Apr 2020 17:08:19 +0200 Subject: [PATCH] Add city outline fetcher script --- scripts/geojson/fetch_city_outlines.sh | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 scripts/geojson/fetch_city_outlines.sh diff --git a/scripts/geojson/fetch_city_outlines.sh b/scripts/geojson/fetch_city_outlines.sh new file mode 100755 index 0000000..3f65b22 --- /dev/null +++ b/scripts/geojson/fetch_city_outlines.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Maps:Cities'` +data=`echo $json | json_reformat | sed -e 's/\\\\n//g' -n -e 's/begin:mapdata\([^}]\+\)/\1/gp' | sed -e "s/|-|/}/g"` + +echo "[" +export IFS="}" +for entry in $data; do + name=`echo $entry | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'` + type=`echo $entry | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'` + coord=`echo $entry | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'` + if [[ "$name" != "" && "$coord" != "" ]]; then + echo "{ \"type\": \"Feature\", + \"geometry\": { + \"type\": \"Polygon\", + \"coordinates\": [[ + $coord + ]] + }, + \"properties\": { + \"name\": \"$name\", + \"type\": \"$type\" + } +}," + fi +done +export IFS=" " +echo "{}" +echo "]"