summaryrefslogtreecommitdiff
path: root/scripts/geojson/maps/fetch_bodiesofwater.sh
blob: 8cd4a29626f9679b21cf380e5752866cc1262649 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 #!/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

	case "$section" in
	"Rivers")
		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\": \"LineString\",
			\"coordinates\": [
				$coord
			]
		},
		\"properties\": {
			\"name\": \"$name\",
			\"type\": \"$type\"
		}
	},"
		fi
	;;
	"Oceans, Seas, and Lakes")
		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
	;;
	esac
done
export IFS=" "
echo "{}"
echo "]"