summaryrefslogtreecommitdiff
path: root/scripts/geojson/maps/fetch_city_outlines.sh
blob: 0e3457274d27627512d60a39229583ac48692210 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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 [[ "$type" == "district" ]]; then
		continue;
	fi
	if [[ "$name" != "" && "$coord" != "" ]]; then
		echo "{ \"type\": \"Feature\",
	\"geometry\": {
		\"type\": \"Polygon\",
		\"coordinates\": [[
			$coord
		]]
	},
	\"properties\": {
		\"name\": \"$name\",
		\"type\": \"$type\"
	}
},"
	fi
done
export IFS=" "
echo "{}"
echo "]"