-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexe_import.sh
executable file
·96 lines (66 loc) · 2.73 KB
/
exe_import.sh
1
2
3
4
5
6
7
8
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#Custom Parameter
modelli_path=/opt/modelli_idro #path containing the script
input_folder=input_dir #name of the folder within the path containing the input dile
db_user=gis #name of the database
db_name=cf #name of the postgres user
srid=903003 #spatial reference adopted by shapefile 903003 is a modification of 3003 (Gauss Boaga Italia coordinates West)
cd $modelli_path/working/
input_files=$modelli_path/$input_folder/*.tar
count=`ls -1 $input_files 2>/dev/null | wc -l`
echo "There are "$count" files to be elaborated "
#Check if at least one file exists
if [ $count != 0 ];
then
#Scan all the tar files in the folder
for fl in $input_files; do
echo " Working on file: "$fl
fn=`basename $fl`
cp $fl $modelli_path/working/
tar xvf $modelli_path/working/$fn >/dev/null
count_img=`ls -1 $modelli_path/working/*.tif 2>/dev/null | wc -l`
if [ $count_img != 0 ];
then
for fl2 in $modelli_path/working/*.tif; do
fn2=`basename $fl2`
#extract data from file
new_name=${fn2:0: ${#fn2}-16 }
res=${fn2:${#fn2}-8: 4}
dd=${fn2:${#fn2}-15: 2}
mm=${fn2:${#fn2}-13: 2}
yy=${fn2:${#fn2}-11: 2}
prod=${fn2:0: 9}
area=${fn2:18: ${#fn2}-34}
echo " Image:" $res $dd $mm $yy $prod $area
rm $modelli_path/raster/$new_name.tif
mv $fl2 $modelli_path/raster/$new_name.tif
psql -h 127.0.0.1 -U $db_user -d $db_name -c "DELETE from modelli_idro.prodotti WHERE produttore='mobidic' AND tipo_prodotto='$prod' AND area='$area' ;" >/dev/null
psql -h 127.0.0.1 -U $db_user -d $db_name -c "insert into modelli_idro.prodotti (produttore, tipo_prodotto, area, res, time_ref, raster) VALUES ('mobidic','$prod','$area',$res, '20$yy-$mm-$dd','$new_name');" >/dev/null
done #End of tif analysis
fi
count_shp=`ls -1 $modelli_path/working/*.shp 2>/dev/null | wc -l`
if [ $count_shp != 0 ];
then
bacino=${fn:12: ${#fn}-16}
bacino2=$(<<< $bacino tr [:lower:] [:upper:])
#name fix for Regione Toscana
if [ "$bacino2" == "OMBRONE" ]; then
bacino2="OMBRONE_GR";
fi
echo "Work on basin shapefile:" $bacino $bacino2
#drop table (if exists)
psql -h 127.0.0.1 -U $db_user -d $db_name -c "DROP TABLE IF EXISTS modelli_idro.mobidic_network_$bacino2;" >/dev/null
#create script and drop table
shp2pgsql -c -s $srid ret_$bacino2.shp modelli_idro.mobidic_network_$bacino2 > net$bacino2.sql
psql -h 127.0.0.1 -U $db_user -d $db_name -f net$bacino2.sql > /dev/null
#remove temporary files
rm ret_$bacino2*
rm net$bacino2.sql
fi
#remove temporary files
rm $modelli_path/working/$fn
rm $fl
done #End of tar file analysis
else
echo "There are no input files"
fi