Project

General

Profile

1
#!/bin/bash
2

    
3
# Bash script to create a new postgis database and prep it with GADM
4
# data for geovalidation purposes.
5
#
6
# Basic workflow:
7
#  1. Load gadm2 data into database
8
#  2. Load geonames data into database
9
#  3. Update geonames to gadm2 data tables
10
# 
11
# Paul Sarando
12
# iPlant Collaborative
13
# Oct 2013
14

    
15
DB_NAME="geoscrub"
16
DB_USER="bien"
17
DB_HOST="localhost"
18
SCRIPT_DIR="$(dirname $0)"
19

    
20
function run_sql_script {
21
    local SCRIPT=$1
22

    
23
    psql -e -U "$DB_USER" -h "$DB_HOST" -d "$DB_NAME" --set ON_ERROR_STOP=1 < "$SCRIPT"
24
    if [[ $? != 0 ]]; then
25
        echo "Error while executing SQL script ${SCRIPT}"
26
        exit 1
27
    fi
28
}
29

    
30
echo "Updating geoscrub validation data."
31

    
32
"${SCRIPT_DIR}"/update_gadm_data.sh
33
if [[ $? != 0 ]]; then
34
    echo "Could not update ${DB_NAME} database with GADM data."
35
    exit 1
36
fi
37

    
38
"${SCRIPT_DIR}"/update_geonames_data.sh
39
if [[ $? != 0 ]]; then
40
    echo "Could not update ${DB_NAME} database with geonames.org data."
41
    exit 1
42
fi
43

    
44
run_sql_script "${SCRIPT_DIR}/geonames-to-gadm.country.sql"
45
run_sql_script "${SCRIPT_DIR}/geonames-to-gadm.stateprovince.sql"
46
run_sql_script "${SCRIPT_DIR}/geonames-to-gadm.county.sql"
47

    
48
echo "Validation data successfully updated."
49

    
(26-26/26)