summaryrefslogtreecommitdiff
path: root/scripts/geojson/maps/fetch_bodiesofwater.sh
blob: 0a2f589f18e26e5542f086b16ba5d7c972400753 (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
33
34
35
36
37
38
39
40
41
42
 #!/bin/bash

json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Maps:BodiesOfWater'`
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

	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 "]"