comparison flys-backend/contrib/import_river.sh @ 5167:a0abb6787ab1

Add first version of import_river script
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 04 Mar 2013 12:45:52 +0100
parents
children 650f94ec3122
comparison
equal deleted inserted replaced
5166:8937dd130230 5167:a0abb6787ab1
1 #!/bin/bash
2 # Import script for rivers
3 #
4 # Authors:
5 # Andre Heinecke <aheinecke@intevation.de>
6 #
7 # Copyright:
8 # Copyright (C) 2012 Greenbone Networks GmbH
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
24 set -e
25
26 # Default settings
27 DEFAULT_HOST=localhost
28 DEFAULT_PORT=1521
29 DEFAULT_USER=flys_dami
30 DEFAULT_PASS=flys_dami
31 DEFAULT_LOG=$PWD/logs
32 DEFAULT_BACKEND_NAME="XE"
33 JAR="hydr_morph/importer.jar"
34 IMPORTER_DRY_RUN=false
35 IMPORTER_MAINVALUE_TYPES=QWTD
36 IMPORTER_ANNOTATION_TYPES="conf/annotation-types.xml"
37
38
39 MIN_MEMORY="8024m"
40
41 OPTIONAL_LIBS="${DIR}"/../opt
42 if [ -d "$OPTIONAL_LIBS" ]; then
43 export PATH="$OPTIONAL_LIBS/bin:$PATH"
44 export LD_LIBRARY_PATH="$OPTIONAL_LIBS/lib:$LD_LIBRARY_PATH"
45 export LD_LIBRARY_PATH="$OPTIONAL_LIBS/lib64:$LD_LIBRARY_PATH"
46 export PYTHONPATH="$OPTIONAL_LIBS/lib/python2.6/site-packages:$PYTHONPATH"
47 export PYTHONPATH="$OPTIONAL_LIBS/lib64/python2.6/site-packages:$PYTHONPATH"
48 export GDAL_DATA="$OPTIONAL_LIBS/share/gdal"
49 fi
50
51 usage(){
52 cat << EOF
53
54 usage: $0 [options] gew_file
55
56 Import a river described by the gew_file
57
58 OPTIONS:
59 -?, --help Show this message
60 -u, --username=<username> Database username. Default: $DEFAULT_USER
61 -w, --password=<password> Database password. Default: $DEFAULT_PASS
62 -h, --host=<host> Connect to database on host <host>.
63 Default: $DEFAULT_HOST
64 -p, --port=<number> Use port number <number>. Default: $DEFAULT_PORT
65 -d, --db-name=<database_name> Name of the database / backend. Default: $DEFAULT_BACKEND_NAME
66 -l, --log-dir=<directory> Directory in which to create the log files.
67 Default: $LOG_DIR
68 --postgres Database is PostgreSQL
69 --skip-hydro Skip import of hydrological data
70 --skip-morpho Skip import of morphological data
71 --skip-geo Skip import of geographic data
72 --skip-wst Skip import of wst data
73 EOF
74 exit 0
75 }
76
77 OPTS=`getopt -o ?u:w:h:p:d: \
78 -l help,username:,password:,host:,port:,db-name:,skip-hydro,skip-morpho,skip-geo,skip-wst \
79 -n $0 -- "$@"`
80 if [ $? != 0 ] ; then usage; fi
81 eval set -- "$OPTS"
82 while true ; do
83 case "$1" in
84 "-?"|"--help")
85 usage;;
86 "--")
87 shift
88 break;;
89 "-u"|"--username")
90 USER=$2
91 shift 2;;
92 "-w"|"--password")
93 PASS=$2
94 shift 2;;
95 "-h"|"--host")
96 HOST=$2
97 shift 2;;
98 "-p"|"--port")
99 PORT=$2
100 shift 2;;
101 "-l"|"--log-dir")
102 LOG=$2
103 shift 2;;
104 "-d"|"--db-name")
105 BACKEND_NAME=$2
106 shift 2;;
107 "--skip-hydro")
108 SKIP_HYDRO="TRUE"
109 shift;;
110 "--skip-morpho")
111 SKIP_MORPHO="TRUE"
112 shift;;
113 "--skip-wst")
114 SKIP_WST="TRUE"
115 shift;;
116 "--skip-geo")
117 SKIP_GEO="TRUE"
118 shift;;
119 "--postgres")
120 POSTGRES="TRUE"
121 shift;;
122 *)
123 echo "Unknown Option $1"
124 usage;;
125 esac
126 done
127
128 if [ -z $USER ]; then
129 USER=$DEFAULT_USER
130 fi
131 if [ -z $PASS ]; then
132 PASS=$DEFAULT_PASS
133 fi
134 if [ -z $PORT ]; then
135 PORT=$DEFAULT_PORT
136 fi
137 if [ -z $HOST ]; then
138 HOST=$DEFAULT_HOST
139 fi
140 if [ -z $BACKEND_NAME ]; then
141 BACKEND_NAME=$DEFAULT_BACKEND_NAME
142 fi
143 if [ -z $LOGDIR ]; then
144 LOG=$DEFAULT_LOG
145 fi
146
147 if [ $# != 1 ]; then
148 usage
149 fi
150
151 if [ ! -r $1 ]; then
152 echo "Could not open $1 please ensure it exists and is readable"
153 fi
154
155 GEW_FILE="$1"
156 RIVER_NAME=$(grep "Gew.sser" "$1" | awk '{print $2}')
157 DATE=$(date +%Y.%m.%d_%H%M)
158 LOG_DIR=${LOG}/${RIVER_NAME}-$DATE
159 mkdir -p ${LOG_DIR}
160
161 if [ "POSTGRES" = "TRUE" ]; then
162 JAR=$(echo "$JAR" | sed 's/importer/importer_psql/')
163 if [ ! -r "$JAR" ]; then
164 echo "Could not find Postgres importer $JAR"
165 exit 1
166 fi
167 OGR_CONNECTION="PG:dbname=$BACKEND_NAME host=$HOST port=$PORT \
168 user=$USER password=$PASS"
169 BACKEND_DB_PREFIX="jdbc:postgresql:"
170 BACKEND_DB_DRIVER="org.postgresql.Driver"
171 BACKEND_DB_DIALECT="org.hibernate.dialect.PostgreSQLDialect"
172 else
173 BACKEND_DB_PREFIX="jdbc:oracle:thin:@"
174 BACKEND_DB_DRIVER="oracle.jdbc.OracleDriver"
175 BACKEND_DB_DIALECT="org.hibernate.dialect.OracleDialect"
176 fi
177
178 BACKEND_URL=$BACKEND_DB_PREFIX//$HOST:$PORT/$BACKEND_NAME
179
180 echo "Importing $RIVER_NAME into $BACKEND_URL."
181
182 import_hydro(){
183 LOG_FILE=${LOG_DIR}/hydro.log
184 echo Importing Hydrological data.
185 echo Logging into: $LOG_FILE
186 sed 's!./import.log!'"$LOG_FILE"'!' conf/log4j.properties > $LOG_DIR/log4j.properties
187 java -jar \
188 -Xmx$MIN_MEMORY \
189 -server \
190 -Dlog4j.configuration=file://$LOG_DIR/log4j.properties \
191 -Dflys.backend.user=$USER \
192 -Dflys.backend.password=$PASS \
193 -Dflys.backend.url=$BACKEND_URL \
194 -Dflys.backend.driver=$BACKEND_DB_DRIVER \
195 -Dflys.backend.dialect=$BACKEND_DB_DIALECT \
196 -Dflys.backend.importer.infogew.file="$GEW_FILE" \
197 -Dflys.backend.main.value.types=$IMPORTER_MAINVALUE_TYPES \
198 -Dflys.backend.importer.annotation.types=$IMPORTER_ANNOTATION_TYPES \
199 -Dflys.backend.importer.dry.run=$IMPORTER_DRY_RUN \
200 -Dflys.backend.importer.skip.annotations=false \
201 -Dflys.backend.importer.skip.bwastr=false \
202 -Dflys.backend.importer.skip.da50s=false \
203 -Dflys.backend.importer.skip.da66s=false \
204 -Dflys.backend.importer.skip.extra.wsts=false \
205 -Dflys.backend.importer.skip.fixations=false \
206 -Dflys.backend.importer.skip.flood.water=false \
207 -Dflys.backend.importer.skip.flood.protection=false \
208 -Dflys.backend.importer.skip.gauges=false \
209 -Dflys.backend.importer.skip.historical.discharge.tables=false \
210 -Dflys.backend.importer.skip.hyks=false \
211 -Dflys.backend.importer.skip.official.lines=false \
212 -Dflys.backend.importer.skip.prfs=false \
213 -Dflys.backend.importer.skip.w80s=false \
214 -Dflys.backend.importer.skip.wst=true \
215 -Dflys.backend.importer.skip.waterlevel.differences=true \
216 -Dflys.backend.importer.skip.waterlevels=true \
217 -Dflys.backend.importer.skip.sq.relation=true \
218 -Dflys.backend.importer.skip.sediment.density=true \
219 -Dflys.backend.importer.skip.sediment.yield=true \
220 -Dflys.backend.importer.skip.morphological.width=true \
221 -Dflys.backend.importer.skip.flow.velocity=true \
222 -Dflys.backend.importer.skip.bed.height.single=true \
223 -Dflys.backend.importer.skip.bed.height.epoch=true \
224 $JAR
225 }
226
227 import_morpho(){
228 LOG_FILE=${LOG_DIR}/morpho.log
229 echo Importing Morphological data.
230 echo Logging into: $LOG_FILE
231 sed 's!./import.log!'"$LOG_FILE"'!' conf/log4j.properties > $LOG_DIR/log4j.properties
232 java -jar \
233 -Xmx$MIN_MEMORY \
234 -server \
235 -Dlog4j.configuration=file://$LOG_DIR/log4j.properties \
236 -Dflys.backend.user=$USER \
237 -Dflys.backend.password=$PASS \
238 -Dflys.backend.url=$BACKEND_URL \
239 -Dflys.backend.driver=$BACKEND_DB_DRIVER \
240 -Dflys.backend.dialect=$BACKEND_DB_DIALECT \
241 -Dflys.backend.importer.infogew.file="$GEW_FILE" \
242 -Dflys.backend.main.value.types=$IMPORTER_MAINVALUE_TYPES \
243 -Dflys.backend.importer.annotation.types=$IMPORTER_ANNOTATION_TYPES \
244 -Dflys.backend.importer.dry.run=$IMPORTER_DRY_RUN \
245 -Dflys.backend.importer.skip.annotations=true \
246 -Dflys.backend.importer.skip.bwastr=true \
247 -Dflys.backend.importer.skip.da50s=true \
248 -Dflys.backend.importer.skip.da66s=true \
249 -Dflys.backend.importer.skip.extra.wsts=true \
250 -Dflys.backend.importer.skip.fixations=true \
251 -Dflys.backend.importer.skip.flood.water=true \
252 -Dflys.backend.importer.skip.flood.protection=true \
253 -Dflys.backend.importer.skip.gauges=true \
254 -Dflys.backend.importer.skip.historical.discharge.tables=true \
255 -Dflys.backend.importer.skip.hyks=true \
256 -Dflys.backend.importer.skip.official.lines=true \
257 -Dflys.backend.importer.skip.prfs=true \
258 -Dflys.backend.importer.skip.w80s=true \
259 -Dflys.backend.importer.skip.wst=true \
260 -Dflys.backend.importer.skip.waterlevel.differences=false \
261 -Dflys.backend.importer.skip.waterlevels=false \
262 -Dflys.backend.importer.skip.sq.relation=false \
263 -Dflys.backend.importer.skip.sediment.density=false \
264 -Dflys.backend.importer.skip.sediment.yield=false \
265 -Dflys.backend.importer.skip.morphological.width=false \
266 -Dflys.backend.importer.skip.flow.velocity=false \
267 -Dflys.backend.importer.skip.bed.height.single=false \
268 -Dflys.backend.importer.skip.bed.height.epoch=false \
269 $JAR
270 }
271
272 import_wst(){
273 LOG_FILE=${LOG_DIR}/wst.log
274 echo Importing WST data.
275 echo Logging into: $LOG_FILE
276 sed 's!./import.log!'"$LOG_FILE"'!' conf/log4j.properties > $LOG_DIR/log4j.properties
277 java -jar \
278 -Xmx$MIN_MEMORY \
279 -server \
280 -Dlog4j.configuration=file://$LOG_DIR/log4j.properties \
281 -Dflys.backend.user=$USER \
282 -Dflys.backend.password=$PASS \
283 -Dflys.backend.url=$BACKEND_URL \
284 -Dflys.backend.driver=$BACKEND_DB_DRIVER \
285 -Dflys.backend.dialect=$BACKEND_DB_DIALECT \
286 -Dflys.backend.importer.infogew.file="$GEW_FILE" \
287 -Dflys.backend.main.value.types=$IMPORTER_MAINVALUE_TYPES \
288 -Dflys.backend.importer.annotation.types=$IMPORTER_ANNOTATION_TYPES \
289 -Dflys.backend.importer.dry.run=$IMPORTER_DRY_RUN \
290 -Dflys.backend.importer.skip.annotations=true \
291 -Dflys.backend.importer.skip.bwastr=true \
292 -Dflys.backend.importer.skip.da50s=true \
293 -Dflys.backend.importer.skip.da66s=true \
294 -Dflys.backend.importer.skip.extra.wsts=true \
295 -Dflys.backend.importer.skip.fixations=true \
296 -Dflys.backend.importer.skip.flood.water=true \
297 -Dflys.backend.importer.skip.flood.protection=true \
298 -Dflys.backend.importer.skip.gauges=true \
299 -Dflys.backend.importer.skip.historical.discharge.tables=true \
300 -Dflys.backend.importer.skip.hyks=true \
301 -Dflys.backend.importer.skip.official.lines=true \
302 -Dflys.backend.importer.skip.prfs=true \
303 -Dflys.backend.importer.skip.w80s=true \
304 -Dflys.backend.importer.skip.wst=false \
305 -Dflys.backend.importer.skip.waterlevel.differences=true \
306 -Dflys.backend.importer.skip.waterlevels=true \
307 -Dflys.backend.importer.skip.sq.relation=true \
308 -Dflys.backend.importer.skip.sediment.density=true \
309 -Dflys.backend.importer.skip.sediment.yield=true \
310 -Dflys.backend.importer.skip.morphological.width=true \
311 -Dflys.backend.importer.skip.flow.velocity=true \
312 -Dflys.backend.importer.skip.bed.height.single=true \
313 -Dflys.backend.importer.skip.bed.height.epoch=true \
314 $JAR
315 }
316
317 import_geo(){
318 LOG_FILE=${LOG_DIR}/geo.log
319 echo Importing Geographic data.
320 echo Logging into: $LOG_FILE
321
322 python $DIR/geodaesie/shpimporter.py \
323 --directory $RIVER_PATH \
324 --river_name $RIVER_NAME \
325 --ogr_connection "$OGR_CONNECTION" \
326 --host $HOST \
327 --user $USER \
328 --password $PASS \
329 --verbose 2 2>&1 > "$LOG_FILE"
330 }
331
332
333 if [ "$SKIP_HYDRO" != "TRUE" ]; then
334 import_hydro
335 fi
336 if [ "$SKIP_WST" != "TRUE" ]; then
337 import_wst
338 fi
339 if [ "$SKIP_MORPHO" != "TRUE" ]; then
340 import_morpho
341 fi
342 if [ "$SKIP_GEO" != "TRUE" ]; then
343 import_geo
344 fi

http://dive4elements.wald.intevation.org