Project

General

Profile

1
#!/bin/bash
2

    
3
# Bash script to download geoscrub_input table dump (created by AMK) from the
4
# vegbien database, and load it into the geoscrub database (i.e., the
5
# postgis database prepped with geonames.org data, GADM2 data, and
6
# associated mapping tables).
7
#
8
# Won't be necessary if we end up injecting all of the geoscrubbing and
9
# geovalidation functionality directly into vegbien itself. And if we
10
# end up implementing this stuff as a standalone service instead, we'd
11
# need to rethink (and generalize) how the input data is handled. But
12
# for now, this should at least serve as a placeholder that could be
13
# tweaked manually to load any arbitrary geoscrub input data table.
14
#
15
# Jim Regetz
16
# NCEAS
17
# Created Nov 2012
18

    
19
# Note, to force data to download from DATA_URL, ensure the DATAFILE is deleted
20
# before running this script.
21

    
22
SCRIPT_DIR=$(dirname $0)
23
DATA_URL="http://fs.vegpath.org/exports/geoscrub_input.no_header.cols=country,stateProvince,county,decimalLatitude,decimalLongitude.csv"
24
DATADIR="${SCRIPT_DIR}/input"
25
DATAFILE="${DATADIR}/geoscrub-corpus.csv"
26

    
27
if [[ ! -d "$DATADIR" ]]; then
28
    echo "making directory ${DATADIR}"
29
    mkdir -p "$DATADIR"
30

    
31
    if [[ $? != 0 ]]; then
32
        echo "Could not create directory ${DATADIR}"
33
        exit 1
34
    fi
35
fi
36

    
37
if [[ ! -r "$DATAFILE" ]]; then
38
    # download distinct records from vegbien
39
    wget -O "$DATAFILE" "$DATA_URL"
40

    
41
    if [[ $? != 0 ]]; then
42
        echo "Could not download input to ${DATAFILE}"
43
        exit 1
44
    fi
45
fi
46

    
47
echo "Loading vegbien data from ${DATAFILE}"
48

    
49
# clear previous data
50
psql -e -d geoscrub --set ON_ERROR_STOP=1 < "${SCRIPT_DIR}/truncate.vegbien_geoscrub.sql"
51
if [[ $? != 0 ]]; then
52
    echo "Could not clear data from vegbien_geoscrub tables."
53
    exit 1
54
fi
55

    
56
# load
57
psql -c "COPY vegbien_geoscrub FROM '${DATAFILE}' WITH CSV" geoscrub
58

    
(12-12/13)