forked from imincik/kataster-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kt-sql
executable file
·153 lines (120 loc) · 3.75 KB
/
kt-sql
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
set -e
if [ $# -ne 1 ]; then
echo
echo "Vykona konverziu dat Katastra do SQL, ESRI Shapefile a Microstation DGN 7."
echo "Pouzitie: `basename $0` <kataster_dir>"
echo
echo "Struktura adresara <kataster_dir>:"
echo " * adresar 'vgi' - subory VGI"
echo " * adresar 'dbf' alebo 'fpu' - subory DBF resp. FPU+FPT"
echo "V pripade, ze existuje adresar 'dbf' aj 'fpu', na konverziu sa pouziju data vo formate FPU."
echo
exit
fi
ROOT_DIR="$(readlink -e $1)"
echo;
echo "PROGRESS:0"
echo "* Vstupny adresar: $ROOT_DIR"
echo;
cd "$ROOT_DIR"
if [ `ls VGI*.zip` ]; then
echo "PROGRESS:3"
echo "Rozbalovanie suborov vo formate ZIP ..."
sleep 5
find -name '*.zip' -exec sh -c 'unzip -o -d "${1%.*}" "$1"' _ {} \;
fi
vgi=`ls -d VGI* | grep -v '.zip'`
spi=`ls -d SPI* | grep -v '.zip'`
test ! -d "$vgi" && { echo "ERROR: Adresar '$ROOT_DIR/vgi' neexistuje. Koncim."; echo; exit 1; }
test ! -d "$spi" && { echo "ERROR: Adresar '$ROOT_DIR/SPI' neexistuje. Koncim."; echo; exit 1; }
echo "PROGRESS:5"
sleep 1
echo "* Cistenie vystupnych adresarov ..."
echo "PROGRESS:10"
sleep 3
echo;
# vycistenie adresarov sql
vystupne_adresare=(sql sql_p sql_g shp dgn log)
for adr in "${vystupne_adresare[@]}"; do
rm -rf $ROOT_DIR/$adr
mkdir -p $ROOT_DIR/$adr
done
cd "$ROOT_DIR"
# cd "$spi"
## ak existuje subor 'fpt' v adresari 'spi', pouzijeme ho na konverziu, inac pouzijeme adresar 'dbf'
#if [ `ls *.fpt` ]; then
##
#### FPU ###
##
#echo "PROGRESS:15"
#sleep 1
#echo "* Konverzia FPU do SQL ..."
#for file in $(find "$spi" -iname "*.fpt"); do
#fpuc=$(sed 's/\.fpt$/\.fpuc/I' <<< $file)
#echo "* Cistenie FPU ($file) ..."
#kt-vycisti_fuvi $file IBM852 > $fpuc || (echo "I: Opakujem cistenie s kodovanim 'CP1250'"; kt-vycisti_fuvi $file CP1250 > $fpuc)
#echo "* Konverzia FPU do SQL ($file) ..."
#kt-import_fuvi $fpuc > $ROOT_DIR/sql_p/$(basename $file).sql
#done;
#else
#
### DBF ###
#
echo "PROGRESS:15"
sleep 1
echo "* Konverzia DBF do SQL ..."
for file in $(find "$spi" -iname "*.DBF"); do
echo "* Konverzia DBF do SQL ($file) ..."
kt-import_dbf2 $file > $ROOT_DIR/sql_p/$(basename $file).sql
done;
#fi
echo "PROGRESS:20"
sleep 1
echo "* Spajanie SQL suborov popisnych dat ..."
find $ROOT_DIR/sql_p -type f -iname *.sql -exec cat "{}" >> sql/popisne_udaje.sql \;
echo;
#
### VGI ###
#
# KN
echo "PROGRESS:25"
sleep 1
echo "* Konverzia KN do SQL (KATUZ, KLADPAR, LINIE, POPIS, ZAPPAR, ZNACKY, ZUOB) ..."
find $vgi -iname "KN*.vgi" -exec kt-vgi2shp -f sql-copy -t -k -l -p -r -n -z -o sql_g "{}" \; &> log/vgi-kn-sql.log
echo "PROGRESS:30"
sleep 1
echo "* Konverzia KN do SHP (vsetky najdene vrstvy)..."
find $vgi -iname "KN*.vgi" -exec kt-vgi2shp -f shp -o shp "{}" \; &> log/vgi-kn-shp.log
echo "PROGRESS:35"
sleep 1
echo "* Konverzia KN do DGN (vsetky najdene vrstvy)..."
find $vgi -iname "KN*.vgi" -exec kt-vgi2shp -f dgn -o dgn "{}" \; &> log/vgi-kn-dgn.log
# UO
echo "PROGRESS:40"
sleep 1
echo "* Konverzia UO do SQL (UOV)..."
find $vgi -iname "UO*.vgi" -exec kt-vgi2shp -f sql-copy -u -o sql_g "{}" \; &> log/vgi-uo-sql.log
echo "PROGRESS:55"
sleep 1
echo "* Konverzia UO do SHP (vsetky najdene vrstvy)..."
find $vgi -iname "UO*.vgi" -exec kt-vgi2shp -f shp -o shp "{}" \; &> log/vgi-uo-shp.log
echo "PROGRESS:65"
sleep 3
echo "* Konverzia UO do DGN (vsetky najdene vrstvy)..."
find $vgi -iname "UO*.vgi" -exec kt-vgi2shp -f dgn -o dgn "{}" \; &> log/vgi-uo-dgn.log
echo "PROGRESS:75"
sleep 3
echo "* Spajanie SQL suborov grafickych dat ..."
find $ROOT_DIR/sql_g -type f -iname *.sql -exec cat "{}" >> sql/graficke_udaje.sql \;
echo;
# logy
echo "PROGRESS:90"
sleep 1
echo "* Chybove hlasenia:"
grep -vH "^INFO\|^$" $ROOT_DIR/log/*.log || true
echo;
# koniec
echo "PROGRESS:100"
echo "* Koniec konverzie"
# vim: set ts=4 sts=4 sw=4 noet: