-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeonames-download.sh
executable file
·43 lines (38 loc) · 1.54 KB
/
geonames-download.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
#!/bin/bash
CONFIG_DIR="$PWD/config"
DATA_DIR="./data"
if [ ! -d "$DATA_DIR" ]; then
mkdir $DATA_DIR
fi
# specify countries to download
country_files="NL BE DE"
cp $CONFIG_DIR/headers-gn.txt $DATA_DIR/geonames.txt
for cfile in $country_files; do
mkdir temp
cd temp
curl -O "https://download.geonames.org/export/dump/$cfile.zip"
unzip "$cfile.zip"
cd ..
cat "temp/$cfile.txt" >> $DATA_DIR/geonames.txt
rm -rf temp
done
# create foreign keys 'adm1' and 'adm2' for the admin1code and admin2code tables
# $9=country code, $11=admin1 code, $12=admin2 code
awk 'BEGIN{FS=OFS="\t"} {print $0, (NR>1 ? $9"."$11 : "adm1"),(NR>1 ? $9"."$11"."$12 : "adm2")}' $DATA_DIR/geonames.txt > $DATA_DIR/geonamesplus.txt
rm $DATA_DIR/geonames.txt
# download latest version of generic files
cp $CONFIG_DIR/headers-feature-codes.txt $DATA_DIR/feature-codes.txt
curl -O "https://download.geonames.org/export/dump/featureCodes_en.txt"
cat featureCodes_en.txt >> $DATA_DIR/feature-codes.txt
rm featureCodes_en.txt
cp $CONFIG_DIR/headers-admin1-codes.txt $DATA_DIR/admin1-codes.txt
curl -O "https://download.geonames.org/export/dump/admin1CodesASCII.txt"
cat admin1CodesASCII.txt >> $DATA_DIR/admin1-codes.txt
rm admin1CodesASCII.txt
cp $CONFIG_DIR/headers-admin2-codes.txt $DATA_DIR/admin2-codes.txt
curl -O "https://download.geonames.org/export/dump/admin2Codes.txt"
# remove double quotes that seem to appear within some strings
# to prevent RML from crashing
sed -i 's/"//g' admin2Codes.txt
cat admin2Codes.txt >> $DATA_DIR/admin2-codes.txt
rm admin2Codes.txt