Newer
Older

User expired
committed
#! /bin/bash
#############################
# This script creates datasets (e.g. from the road network of bolzano)
# from data that is downloaded from osm (OpenStreetMap) and then imported
# into the postgis database.

User expired
committed
#
# In difference to importData.sh this only creates the given datasets with the
# given SRIDs by impoering them into postgis.

User expired
committed
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
66
67
68
69
70
71
72
73
74
#
# Note that you need some synlinks in directoy /opt/ (to isochrone-datamodel
# and isochrone-tools project) for this script to work correctly.
#############################
if [ "$EUID" -ne "0" ]; then
echo '- This script must be run as root!'
exit 1
fi
########################################################################
# Config import (so we can override some things like working directory #
########################################################################
SCRIPT="$(readlink -f ${BASH_SOURCE[0]})"
CURRENT_DIR="$(dirname ${SCRIPT})"
SCRIPT_DIR="${CURRENT_DIR}/../bootstrap"
if [ ! -f "${SCRIPT_DIR}/config.sh" ]; then
# If config.properties is not besides the bash-script (most likely because vagrant uploaded it into the guest)
# we will try to find it in the shared folder
SCRIPT_DIR="/vagrant/bootstrap"
fi
if [ ! -f "${SCRIPT_DIR}/config.sh" ]; then
echo '- No variable declarations found (config.properties file not found)!'
exit 1;
fi
source "${SCRIPT_DIR}/config.sh"
############################
# Precondition checks #
############################
if ! $AVAILABLE_ISOCHRONE_DATAMODEL; then
echo " - Project folder isochrone-datamodel not present in directory '${DEPLOY_DIR}'"
exit 1
fi
if ! $AVAILABLE_ISOCHRONE_TOOLS; then
echo " - Project archive isochrone-tools not present in directory '${DEPLOY_DIR}'"
exit 1
fi
if ! $AVAILABLE_POSTGRES; then
echo " - PostgreSQL database not installed on this system"
exit 1
fi
if ! $AVAILABLE_POSTGIS; then
echo " - Postgis extension not installed on this system"
exit 1
fi
############################
# Variable definitions #
############################
DATASET_SRID="${1}"
DATASET_CITY="${2}"
PG_DB_USER="${3}"
PG_DB_PASSWORD="${4}"
UPDATE_DATA=true
WORKING_DIR="${CURRENT_DIR}"
source "${SCRIPT_DIR}/importData.sh" "${PG_DB_USER}" "${PG_DB_PASSWORD}" "false" "false"
#####################
# Dataset creation #
#####################

User expired
committed
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Creating datasets ($(date +%H:%M:%S)):"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
START=$(date +%s)
mkdir -p "${DATA_DIR}"
mkdir -p "${DOWNLOAD_DIR}"
mkdir -p "${WORKING_DIR}"
cd "${WORKING_DIR}"
# Delete old log files
find . -type f -name "*.log" -delete
# Create datasets
CITY_ARR=(${DATASET_CITY//,/ })
SRID_ARR=(${DATASET_SRID//,/ })
for CURRENT_CITY in "${CITY_ARR[@]}"; do
for CURRENT_SRID in "${SRID_ARR[@]}"; do
echo "Creating dataset for city \"${CURRENT_CITY}\" (SRID: ${CURRENT_SRID})"

User expired
committed
fn_import_dataset_postgis "${CURRENT_CITY}" "${CURRENT_SRID}"
done
done
END=$(date +%s)
TOTAL=$(( $END - $START ))
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Datasets created in directory '${DATA_DIR}'"
echo " Datasets with are still present in the database (only with the last srid specified)"
printf ' Time to create the datasets: %dh:%dm:%ds\n' $(($TOTAL/3600)) $(($TOTAL%3600/60)) $(($TOTAL%60))

User expired
committed
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"