Skip to content
Snippets Groups Projects
createDataset.sh 3.33 KiB
Newer Older
# 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.
# In difference to importData.sh this only creates the given datasets with the
# given SRIDs by impoering them into postgis.
#
# 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  #
#####################

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})"
		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))
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"