-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.sh
executable file
·65 lines (56 loc) · 1.21 KB
/
data.sh
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
63
64
65
#!/bin/bash
set -e -u
usage() {
echo "Usage: data.sh [-d directory] [-t directory] [-h]"
echo
echo "-d - Download administrative boundaries from INEGI into directory"
echo "-t - Transform INEGI into GeoJSON."
echo "-h - This help text."
echo
}
parse_options() {
set -- "$@"
if [ "$#" -eq 0 ]; then
usage
exit 0
fi
while [ "$#" -ne 0 ]
do
case $1 in
-d) echo "Downloading data from INEGI to $2 directory"
mkdir -p $2
cd $2
download
cd ..
shift 1
;;
-t) echo "Transforming data into GeoJSON"
cd $2
transform
cd ..
shift 1
;;
-h) usage
exit 0
;;
?*) echo "ERROR: Unknown option."
usage
exit 0
;;
esac
shift 1
done
}
download() {
wget -O - http://mapserver.inegi.org.mx/MGN/mge2014v6_2.zip > s.zip
wget -O - http://mapserver.inegi.org.mx/MGN/mgm2014v6_2.zip > m.zip
unzip s.zip
unzip m.zip
}
transform() {
rm -f states.json municipalities.json
ogr2ogr -f GeoJSON states.json mge2015v6_2.shp -progress
ogr2ogr -f GeoJSON municipalities.json mgm2015v6_2.shp -progress
}
parse_options "$@"
# vi: expandtab sw=2 ts=2