Skip to content

Commit a05b4cd

Browse files
committed
updated 3DCityDB scripts
1 parent aa86abc commit a05b4cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+194
-96
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env bash
2+
# 3DCityDB setup --------------------------------------------------------------
3+
4+
# Print commands and their arguments as they are executed
5+
set -e;
6+
7+
# psql should stop on error
8+
psql=( psql -v ON_ERROR_STOP=1 )
9+
10+
# SRID ------------------------------------------------------------------------
11+
regex_numeric='^[0-9]+$'
12+
if [ -z ${SRID+x} ]; then
13+
# No SRID set -> give instructions on how to create a DB and do nothing
14+
echo
15+
echo "SRID is not set. No 3DCityDB instance will be created in database '$POSTGRES_DB'."
16+
exit
17+
else
18+
# SRID given, check if valid
19+
if [[ ! $SRID =~ $regex_numeric ]] || [ $SRID -le 0 ]; then
20+
echo
21+
echo 'Illegal input! Enter a positive integer for the SRID.'
22+
fi
23+
fi
24+
25+
# SRS_NAME --------------------------------------------------------------------
26+
if [ -z ${SRS_NAME+x} ]; then
27+
# SRS_NAME unset, set default SRS_NAME using HEIGHT_EPSG if set
28+
# HEIGHT EPSG ---------------------------------------------------------------
29+
if [ -z ${HEIGHT_EPSG+x} ]; then
30+
# No HEIGHT_EPSG given
31+
SRS_NAME="urn:ogc:def:crs:EPSG::$SRID"
32+
else
33+
if [ $HEIGHT_EPSG -gt 0 ]; then
34+
SRS_NAME="urn:ogc:def:crs,crs:EPSG::$SRID,crs:EPSG::$HEIGHT_EPSG"
35+
else
36+
SRS_NAME="urn:ogc:def:crs:EPSG::$SRID"
37+
fi
38+
fi
39+
else
40+
if [ ! -z ${HEIGHT_EPSG+x} ]; then
41+
# SRS_NAME is set, HEIGHT_EPSG is ignored
42+
echo
43+
echo "!!! WARNING: SRS_NAME is set. HEIGHT_EPSG will be ignored."
44+
fi
45+
fi
46+
47+
# Add PostGIS raster extension ------------------------------------------------
48+
# Get major version from POSTGIS_VERSION, POSTGIS_MAJOR may return string
49+
postgis_major=$( echo $POSTGIS_VERSION | cut -f1 -d '.' )
50+
if [ $postgis_major -gt 2 ]; then
51+
echo
52+
echo "Create PostGIS raster extensions in database '$POSTGRES_DB' ..."
53+
54+
"${psql[@]}" -d "$POSTGRES_DB" -c "CREATE EXTENSION IF NOT EXISTS postgis_raster;"
55+
56+
echo "Create PostGIS raster extensions in database '$POSTGRES_DB' ...done!"
57+
fi
58+
59+
# Add PostGIS SFCGAL extension ------------------------------------------------
60+
if [ ! -z ${POSTGIS_SFCGAL+x} ] && [ ${POSTGIS_SFCGAL} = true ] || [ "${POSTGIS_SFCGAL}" = "yes" ] ; then
61+
62+
echo "Create PostGIS SFCGAL extensions in database '$POSTGRES_DB' ..."
63+
64+
"${psql[@]}" -d "$POSTGRES_DB" -c "CREATE EXTENSION IF NOT EXISTS postgis_sfcgal;"
65+
66+
echo "Create PostGIS SFCGAL extensions in database '$POSTGRES_DB' ...done!"
67+
SFCGAL=true
68+
else
69+
SFCGAL=false
70+
fi
71+
72+
# Setup 3DCityDB schema -------------------------------------------------------
73+
echo
74+
echo "Setting up 3DCityDB database schema in database '$POSTGRES_DB' ..."
75+
76+
"${psql[@]}" -d "$POSTGRES_DB" -f "create-db.sql" \
77+
-v srid="$SRID" -v srs_name="$SRS_NAME" > /dev/null
78+
79+
echo "Setting up 3DCityDB database schema in database '$POSTGRES_DB' ...done!"
80+
81+
# Echo info -------------------------------------------------------------------
82+
cat <<EOF
83+
84+
# 3DCityDB Docker PostGIS ######################################################
85+
#
86+
# PostgreSQL/PostGIS -----------------------------------------------------------
87+
# PostgreSQL version $PG_MAJOR - $PG_VERSION
88+
# PostGIS version $POSTGIS_VERSION
89+
#
90+
# 3DCityDB ---------------------------------------------------------------------
91+
# https://github.com/3dcitydb/3dcitydb
92+
#
93+
# 3DCityDB version $CITYDBVERSION
94+
# DBNAME $POSTGRES_DB
95+
# SRID $SRID
96+
# SRSNAME $SRS_NAME
97+
# HEIGHT_EPSG $HEIGHT_EPSG
98+
# SFCGAL enabled $SFCGAL
99+
#
100+
# Maintainer -------------------------------------------------------------------
101+
# Bruno Willenborg
102+
# Chair of Geoinformatics
103+
# Department of Aerospace and Geodesy
104+
# Technical University of Munich (TUM)
105+
# b.willenborg(at)tum.de
106+
#
107+
################################################################################
108+
109+
EOF
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
#!/bin/bash
22
# Provide your database details here ------------------------------------------
3-
#: '
43
export PGBIN=path_to_psql
54
export PGHOST=your_host_address
65
export PGPORT=5432
76
export CITYDB=your_database
87
export PGUSER=your_username
9-
#'
10-
: '
11-
export PGBIN=/usr/bin/psql
12-
export PGHOST=localhost
13-
export PGPORT=5432
14-
export CITYDB=local23
15-
export PGUSER=postgres
16-
'
178
#------------------------------------------------------------------------------

resources/3dcitydb/postgresql/ShellScripts/Unix/CREATE_DB.sh renamed to resources/3dcitydb/postgresql/shell-scripts/unix/create-db.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# on PostgreSQL/PostGIS
44

55
# read database connection details
6-
source CONNECTION_DETAILS.sh
6+
source connection-details.sh
77

88
# add PGBIN to PATH
99
export PATH="$PGBIN:$PATH"
@@ -38,7 +38,7 @@ echo
3838
echo '######################################################################################'
3939

4040
# cd to path of the SQL scripts
41-
cd ../../SQLScripts
41+
cd ../../sql-scripts
4242

4343
# Prompt for SRID -------------------------------------------------------------
4444
re='^[0-9]+$'
@@ -83,10 +83,10 @@ echo 'Please enter the corresponding SRS name to be used in exports.'
8383
read -p "(default SRS_NAME=$SRS_NAME): " var
8484
SRS_NAME=${var:-$SRS_NAME}
8585

86-
# Run CREATE_DB.sql to create the 3D City Database instance -------------------
86+
# Run create-db.sql to create the 3D City Database instance -------------------
8787
echo
8888
echo "Connecting to \"$PGUSER@$PGHOST:$PGPORT/$CITYDB\" ..."
89-
psql -d "$CITYDB" -f "CREATE_DB.sql" -v srid="$SRID" -v srs_name="$SRS_NAME"
89+
psql -d "$CITYDB" -f "create-db.sql" -v srid="$SRID" -v srs_name="$SRS_NAME"
9090

9191
echo
9292
read -rsn1 -p 'Press ENTER to quit.'

resources/3dcitydb/postgresql/ShellScripts/Unix/CREATE_SCHEMA.sh renamed to resources/3dcitydb/postgresql/shell-scripts/unix/create-schema.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# on PostgreSQL/PostGIS
44

55
# read database connection details
6-
source CONNECTION_DETAILS.sh
6+
source connection-details.sh
77

88
# add PGBIN to PATH
99
export PATH="$PGBIN:$PATH"
@@ -38,12 +38,12 @@ echo
3838
echo '#####################################################################################'
3939

4040
# cd to path of the SQL scripts
41-
cd ../../SQLScripts/UTIL/SCHEMAS
41+
cd ../../sql-scripts
4242

4343
# List the existing 3DCityDB schemas ------------------------------------------
4444
echo
4545
echo "Reading 3DCityDB schemas from \"$PGUSER@$PGHOST:$PGPORT/$CITYDB\" ..."
46-
psql -d "$CITYDB" -f "LIST_SCHEMAS.sql"
46+
psql -d "$CITYDB" -f "util/list-schemas.sql"
4747

4848
if [[ $? -ne 0 ]] ; then
4949
echo 'Failed to read 3DCityDB schemas from database.'
@@ -58,10 +58,10 @@ echo 'Please enter the name of the 3DCityDB schema you want to create.'
5858
read -p "(default SCHEMA_NAME=$SCHEMA_NAME): " var
5959
SCHEMA_NAME=${var:-$SCHEMA_NAME}
6060

61-
# Run CREATE_SCHEMA.sql to create a new 3DCityDB schema -----------------------
61+
# Run create-schema.sql to create a new 3DCityDB schema -----------------------
6262
echo
6363
echo "Connecting to \"$PGUSER@$PGHOST:$PGPORT/$CITYDB\" ..."
64-
psql -d "$CITYDB" -f "CREATE_SCHEMA.sql" -v schema_name="$SCHEMA_NAME"
64+
psql -d "$CITYDB" -f "create-schema.sql" -v schema_name="$SCHEMA_NAME"
6565

6666
echo
6767
read -rsn1 -p 'Press ENTER to quit.'

resources/3dcitydb/postgresql/ShellScripts/Unix/DROP_DB.sh renamed to resources/3dcitydb/postgresql/shell-scripts/unix/drop-db.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# on PostgreSQL/PostGIS
44

55
# read database connection details
6-
source CONNECTION_DETAILS.sh
6+
source connection-details.sh
77

88
# add PGBIN to PATH
99
export PATH="$PGBIN:$PATH"
@@ -36,12 +36,12 @@ echo
3636
echo '################################################################################'
3737

3838
# cd to path of the SQL scripts
39-
cd ../../SQLScripts
39+
cd ../../sql-scripts
4040

41-
# Run DROP_DB.sql to drop the 3D City Database instance -----------------------
41+
# Run drop-db.sql to drop the 3D City Database instance -----------------------
4242
echo
4343
echo "Connecting to \"$PGUSER@$PGHOST:$PGPORT/$CITYDB\" ..."
44-
psql -d "$CITYDB" -f "DROP_DB.sql"
44+
psql -d "$CITYDB" -f "drop-db.sql"
4545

4646
echo
4747
read -rsn1 -p 'Press ENTER to quit.'

resources/3dcitydb/postgresql/ShellScripts/Unix/DROP_SCHEMA.sh renamed to resources/3dcitydb/postgresql/shell-scripts/unix/drop-schema.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# on PostgreSQL/PostGIS
44

55
# read database connection details
6-
source CONNECTION_DETAILS.sh
6+
source connection-details.sh
77

88
# add PGBIN to PATH
99
export PATH="$PGBIN:$PATH"
@@ -38,12 +38,12 @@ echo
3838
echo '############################################################################'
3939

4040
# cd to path of the SQL scripts
41-
cd ../../SQLScripts/UTIL/SCHEMAS
41+
cd ../../sql-scripts
4242

4343
# List the existing 3DCityDB schemas ------------------------------------------
4444
echo
4545
echo "Reading 3DCityDB schemas from \"$PGUSER@$PGHOST:$PGPORT/$CITYDB\" ..."
46-
psql -d "$CITYDB" -f "LIST_SCHEMAS.sql"
46+
psql -d "$CITYDB" -f "util/list-schemas.sql"
4747

4848
if [[ $? -ne 0 ]] ; then
4949
echo 'Failed to read 3DCityDB schemas from database.'
@@ -66,10 +66,10 @@ while [ 1 ]; do
6666
fi
6767
done;
6868

69-
# Run DROP_SCHEMA.sql to remove the selected 3DCityDB schema ------------------
69+
# Run drop-schema.sql to remove the selected 3DCityDB schema ------------------
7070
echo
7171
echo "Connecting to \"$PGUSER@$PGHOST:$PGPORT/$CITYDB\" ..."
72-
psql -d "$CITYDB" -f "DROP_SCHEMA.sql" -v schema_name="$SCHEMA_NAME"
72+
psql -d "$CITYDB" -f "drop-schema.sql" -v schema_name="$SCHEMA_NAME"
7373

7474
echo
7575
read -rsn1 -p 'Press ENTER to quit.'

resources/3dcitydb/postgresql/ShellScripts/Unix/GRANT_ACCESS.sh renamed to resources/3dcitydb/postgresql/shell-scripts/unix/grant-access.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# on PostgreSQL/PostGIS
44

55
# read database connection details
6-
source CONNECTION_DETAILS.sh
6+
source connection-details.sh
77

88
# add PGBIN to PATH
99
export PATH="$PGBIN:$PATH"
@@ -40,7 +40,7 @@ echo
4040
echo '####################################################################################'
4141

4242
# cd to path of the SQL scripts
43-
cd ../../SQLScripts/UTIL/GRANT_ACCESS
43+
cd ../../sql-scripts
4444

4545
# Prompt for GRANTEE ----------------------------------------------------------
4646
while [ 1 ]; do
@@ -59,7 +59,7 @@ done
5959
# List the existing 3DCityDB schemas ------------------------------------------
6060
echo
6161
echo "Reading 3DCityDB schemas from \"$PGUSER@$PGHOST:$PGPORT/$CITYDB\" ..."
62-
psql -d "$CITYDB" -f "../SCHEMAS/LIST_SCHEMAS.sql"
62+
psql -d "$CITYDB" -f "util/list-schemas.sql"
6363

6464
if [[ $? -ne 0 ]] ; then
6565
echo 'Failed to read 3DCityDB schemas from database.'
@@ -92,10 +92,10 @@ while [ 1 ]; do
9292
fi
9393
done
9494

95-
# Run GRANT_ACCESS.sql to grant access privileges on a specific schema --------
95+
# Run grant-access.sql to grant access privileges on a specific schema --------
9696
echo
9797
echo "Connecting to \"$PGUSER@$PGHOST:$PGPORT/$CITYDB\" ..."
98-
psql -d "$CITYDB" -f "GRANT_ACCESS.sql" -v username="$GRANTEE" -v schema_name="$SCHEMA_NAME" -v access_mode="$ACCESS_MODE"
98+
psql -d "$CITYDB" -f "grant-access.sql" -v username="$GRANTEE" -v schema_name="$SCHEMA_NAME" -v access_mode="$ACCESS_MODE"
9999

100100
echo
101101
read -rsn1 -p 'Press ENTER to quit.'

resources/3dcitydb/postgresql/ShellScripts/Unix/REVOKE_ACCESS.sh renamed to resources/3dcitydb/postgresql/shell-scripts/unix/revoke-access.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# on PostgreSQL/PostGIS
44

55
# read database connection details
6-
source CONNECTION_DETAILS.sh
6+
source connection-details.sh
77

88
# add PGBIN to PATH
99
export PATH="$PGBIN:$PATH"
@@ -40,7 +40,7 @@ echo
4040
echo '#######################################################################################'
4141

4242
# cd to path of the SQL scripts
43-
cd ../../SQLScripts/UTIL/GRANT_ACCESS
43+
cd ../../sql-scripts
4444

4545
# Prompt for GRANTEE ----------------------------------------------------------
4646
while [ 1 ]; do
@@ -59,7 +59,7 @@ done
5959
# List the 3DCityDB schemas granted to GRANTEE --------------------------------
6060
echo
6161
echo "Reading 3DCityDB schemas granted to \"$GRANTEE\" from \"$PGUSER@$PGHOST:$PGPORT/$CITYDB\" ..."
62-
psql -d "$CITYDB" -f "../SCHEMAS/LIST_SCHEMAS_WITH_ACCESS_GRANT.sql" -v username="$GRANTEE"
62+
psql -d "$CITYDB" -f "util/list-schemas-with-access-grant.sql" -v username="$GRANTEE"
6363

6464
if [[ $? -ne 0 ]] ; then
6565
echo 'Failed to read 3DCityDB schemas from database.'
@@ -74,10 +74,10 @@ echo "Please enter the name of the 3DCityDB schema that shall be revoked from \"
7474
read -p "(default SCHEMA_NAME=$SCHEMA_NAME): " var
7575
SCHEMA_NAME=${var:-$SCHEMA_NAME}
7676

77-
# Run REVOKE_ACCESS.sql to revoke read-only access on a specific schema -------
77+
# Run revoke-access.sql to revoke read-only access on a specific schema -------
7878
echo
7979
echo "Connecting to \"$PGUSER@$PGHOST:$PGPORT/$CITYDB\" ..."
80-
psql -d "$CITYDB" -f "REVOKE_ACCESS.sql" -v username="$GRANTEE" -v schema_name="$SCHEMA_NAME"
80+
psql -d "$CITYDB" -f "revoke-access.sql" -v username="$GRANTEE" -v schema_name="$SCHEMA_NAME"
8181

8282
echo
8383
read -rsn1 -p 'Press ENTER to quit.'

resources/3dcitydb/postgresql/ShellScripts/Windows/CREATE_DB.bat renamed to resources/3dcitydb/postgresql/shell-scripts/windows/create-db.bat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
:: on PostgreSQL/PostGIS
44

55
:: read database connection details
6-
call CONNECTION_DETAILS.bat
6+
call connection-details.bat
77

88
:: add PGBIN to PATH
99
set PATH=%PGBIN%;%PATH%;%SYSTEMROOT%\System32
@@ -38,7 +38,7 @@ echo.
3838
echo ######################################################################################
3939

4040
:: cd to path of the SQL scripts
41-
cd ..\..\SQLScripts
41+
cd ..\..\sql-scripts
4242

4343
:: Prompt for SRID ------------------------------------------------------------
4444
:srid
@@ -100,9 +100,9 @@ set /p var="(default SRS_NAME=%SRS_NAME%): "
100100

101101
if /i not "%var%"=="" set SRS_NAME=%var%
102102

103-
:: Run CREATE_DB.sql to create the 3D City Database instance ------------------
103+
:: Run create-db.sql to create the 3D City Database instance ------------------
104104
echo.
105105
echo Connecting to "%PGUSER%@%PGHOST%:%PGPORT%/%CITYDB%" ...
106-
psql -d "%CITYDB%" -f "CREATE_DB.sql" -v srid="%SRID%" -v srs_name="%SRS_NAME%"
106+
psql -d "%CITYDB%" -f "create-db.sql" -v srid="%SRID%" -v srs_name="%SRS_NAME%"
107107

108108
pause

0 commit comments

Comments
 (0)