1 | #!/bin/bash |
---|
2 | |
---|
3 | source psql.conf |
---|
4 | |
---|
5 | # Die zu verarbeitendenden Tabellen |
---|
6 | # gefolgt vom entsprechenden Geometrietyp |
---|
7 | # |
---|
8 | # TODO: saubere Array-Struktur ... |
---|
9 | |
---|
10 | # PROBLEM: unterschiedliche (Anzahl) Spalten: |
---|
11 | # wenn alles pauschal prozessiert wird, |
---|
12 | # werden alle Spalten abgesehen von 'wkb_geometry' und |
---|
13 | # 'widmung' nicht berÃŒcksichtigt! |
---|
14 | # Workaround: auxfields... |
---|
15 | |
---|
16 | tables=('map_wald_g0') |
---|
17 | geomtype=('ST_Polygon') |
---|
18 | auxfields=('') |
---|
19 | |
---|
20 | tables+=('map_wald_g1') |
---|
21 | geomtype+=('ST_Polygon') |
---|
22 | auxfields+=('') |
---|
23 | |
---|
24 | tables+=('map_wald_g2') |
---|
25 | geomtype+=('ST_Polygon') |
---|
26 | auxfields+=('') |
---|
27 | |
---|
28 | tables+=('map_wald_g3') |
---|
29 | geomtype+=('ST_Polygon') |
---|
30 | auxfields+=('') |
---|
31 | |
---|
32 | tables+=('map_wald_g4') |
---|
33 | geomtype+=('ST_Polygon') |
---|
34 | auxfields+=('') |
---|
35 | |
---|
36 | tables+=('map_wald_g5') |
---|
37 | geomtype+=('ST_Polygon') |
---|
38 | auxfields+=('') |
---|
39 | |
---|
40 | tables+=('map_wald_g6') |
---|
41 | geomtype+=('ST_Polygon') |
---|
42 | auxfields+=('') |
---|
43 | |
---|
44 | tables+=('map_fluesse_g0') |
---|
45 | geomtype+=('ST_Polygon') |
---|
46 | auxfields+=('') |
---|
47 | |
---|
48 | tables+=('map_fluesse_g1') |
---|
49 | geomtype+=('ST_Polygon') |
---|
50 | auxfields+=('') |
---|
51 | |
---|
52 | tables+=('map_fluesse_g2') |
---|
53 | geomtype+=('ST_Polygon') |
---|
54 | auxfields+=('') |
---|
55 | |
---|
56 | tables+=('map_fluesse_g3') |
---|
57 | geomtype+=('ST_Polygon') |
---|
58 | auxfields+=('') |
---|
59 | |
---|
60 | tables+=('map_fluesse_g4') |
---|
61 | geomtype+=('ST_Polygon') |
---|
62 | auxfields+=('') |
---|
63 | |
---|
64 | tables+=('map_fluesse_g5') |
---|
65 | geomtype+=('ST_Polygon') |
---|
66 | auxfields+=('') |
---|
67 | |
---|
68 | tables+=('map_fluesse_g6') |
---|
69 | geomtype+=('ST_Polygon') |
---|
70 | auxfields+=('') |
---|
71 | |
---|
72 | tables+=('map_baeche_g0') |
---|
73 | geomtype+=('ST_LineString') |
---|
74 | auxfields+=('') |
---|
75 | |
---|
76 | tables+=('map_baeche_g1') |
---|
77 | geomtype+=('ST_LineString') |
---|
78 | auxfields+=('') |
---|
79 | |
---|
80 | tables+=('map_baeche_g2') |
---|
81 | geomtype+=('ST_LineString') |
---|
82 | auxfields+=('') |
---|
83 | |
---|
84 | tables+=('map_baeche_g3') |
---|
85 | geomtype+=('ST_LineString') |
---|
86 | auxfields+=('') |
---|
87 | |
---|
88 | tables+=('map_baeche_g4') |
---|
89 | geomtype+=('ST_LineString') |
---|
90 | auxfields+=('') |
---|
91 | |
---|
92 | tables+=('map_baeche_g5') |
---|
93 | geomtype+=('ST_LineString') |
---|
94 | auxfields+=('') |
---|
95 | |
---|
96 | tables+=('map_baeche_g6') |
---|
97 | geomtype+=('ST_LineString') |
---|
98 | auxfields+=('') |
---|
99 | |
---|
100 | tables+=('map_strasse_g0') |
---|
101 | geomtype+=('ST_LineString') |
---|
102 | auxfields+=('name_, bezeichnung,') |
---|
103 | |
---|
104 | tables+=('map_strasse_g1') |
---|
105 | geomtype+=('ST_LineString') |
---|
106 | auxfields+=('name_, bezeichnung,') |
---|
107 | |
---|
108 | tables+=('map_strasse_g2') |
---|
109 | geomtype+=('ST_LineString') |
---|
110 | auxfields+=('name_, bezeichnung,') |
---|
111 | |
---|
112 | tables+=('map_strasse_g3') |
---|
113 | geomtype+=('ST_LineString') |
---|
114 | auxfields+=('name_, bezeichnung,') |
---|
115 | |
---|
116 | tables+=('map_strasse_g4') |
---|
117 | geomtype+=('ST_LineString') |
---|
118 | auxfields+=('name_, bezeichnung,') |
---|
119 | |
---|
120 | tables+=('map_strasse_g5') |
---|
121 | geomtype+=('ST_LineString') |
---|
122 | auxfields+=('name_, bezeichnung,') |
---|
123 | |
---|
124 | tables+=('map_strasse_g6') |
---|
125 | geomtype+=('ST_LineString') |
---|
126 | auxfields+=('name_, bezeichnung,') |
---|
127 | |
---|
128 | tables+=('map_wege_g0') |
---|
129 | geomtype+=('ST_LineString') |
---|
130 | auxfields+=('') |
---|
131 | |
---|
132 | tables+=('map_wege_g1') |
---|
133 | geomtype+=('ST_LineString') |
---|
134 | auxfields+=('') |
---|
135 | |
---|
136 | tables+=('map_wege_g2') |
---|
137 | geomtype+=('ST_LineString') |
---|
138 | auxfields+=('') |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | # Es können auch noch andere DatensÀtze hier geclippt werden. |
---|
144 | # Einfach danach auch das $cells-Array entsprechend erweitern. |
---|
145 | |
---|
146 | # Die zu verwendenden Kacheln: g0=2km, g1=5km, g2=10km, g3=25km, g4=50km |
---|
147 | cells=('map_landesflaeche_g0') #wald_g0 |
---|
148 | cells+=('map_landesflaeche_g0') #wald_g1 |
---|
149 | cells+=('map_landesflaeche_g1') #wald_g2 |
---|
150 | cells+=('map_landesflaeche_g1') #wald_g3 |
---|
151 | cells+=('map_landesflaeche_g2') #wald_g4 |
---|
152 | cells+=('map_landesflaeche_g3') #wald_g5 |
---|
153 | cells+=('map_landesflaeche_g4') #wald_g6 |
---|
154 | |
---|
155 | cells+=('map_landesflaeche_g0') #fluesse_g0 |
---|
156 | cells+=('map_landesflaeche_g0') #fluesse_g1 |
---|
157 | cells+=('map_landesflaeche_g1') #fluesse_g2 |
---|
158 | cells+=('map_landesflaeche_g1') #fluesse_g3 |
---|
159 | cells+=('map_landesflaeche_g2') #fluesse_g4 |
---|
160 | cells+=('map_landesflaeche_g3') #fluesse_g5 |
---|
161 | cells+=('map_landesflaeche_g4') #fluesse_g6 |
---|
162 | |
---|
163 | cells+=('map_landesflaeche_g0') #baeche_g0 |
---|
164 | cells+=('map_landesflaeche_g0') #baeche_g1 |
---|
165 | cells+=('map_landesflaeche_g1') #baeche_g2 |
---|
166 | cells+=('map_landesflaeche_g1') #baeche_g3 |
---|
167 | cells+=('map_landesflaeche_g2') #baeche_g4 |
---|
168 | cells+=('map_landesflaeche_g3') #baeche_g5 |
---|
169 | cells+=('map_landesflaeche_g4') #baeche_g6 |
---|
170 | |
---|
171 | cells+=('map_landesflaeche_g0') #strasse_g0 |
---|
172 | cells+=('map_landesflaeche_g0') #strasse_g1 |
---|
173 | cells+=('map_landesflaeche_g1') #strasse_g2 |
---|
174 | cells+=('map_landesflaeche_g1') #strasse_g3 |
---|
175 | cells+=('map_landesflaeche_g2') #strasse_g4 |
---|
176 | cells+=('map_landesflaeche_g3') #strasse_g5 |
---|
177 | cells+=('map_landesflaeche_g4') #strasse_g6 |
---|
178 | |
---|
179 | cells+=('map_landesflaeche_g0') #wege_g0 |
---|
180 | cells+=('map_landesflaeche_g0') #wege_g1 |
---|
181 | cells+=('map_landesflaeche_g1') #wege_g2 |
---|
182 | #################################################################### |
---|
183 | # ab hier nichts mehr Àndern |
---|
184 | # do not change anything below this line. |
---|
185 | #################################################################### |
---|
186 | |
---|
187 | # Festlegen der Datenbank-Verbindung |
---|
188 | echo "Teste PostGIS-Verbindung zu $dbname auf $dbuser@$dbhost:$dbport:" |
---|
189 | if [ $dbpass == false ]; then |
---|
190 | CONN="psql --user=$dbuser $dbname --host=$dbhost --port=$dbport -w" |
---|
191 | else |
---|
192 | CONN="psql --user=$dbuser $dbname --host=$dbhost --port=$dbport --password=$dbpass" |
---|
193 | fi |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | #### SCHLEIFE ÃŒber tables #### |
---|
199 | echo ${#tables[@]} |
---|
200 | for (( x=0 ; x < ${#tables[@]}; x++ )) |
---|
201 | do |
---|
202 | echo -e "\n-----------------------------------------------------------------" |
---|
203 | echo "Prozessiere ${tables[$x]}:" |
---|
204 | |
---|
205 | QUERY="${CONN} -c 'SELECT true FROM ${tables[$x]} LIMIT 1 OFFSET 0' --quiet" |
---|
206 | |
---|
207 | if eval $QUERY &> /dev/null; |
---|
208 | then |
---|
209 | echo " Verbindung erfolgreich hergestellt, Eingabetabelle existiert." |
---|
210 | else # Kein Abruf von Tabelle möglich - DB-Konfig falsch oder Tabelle nicht existent |
---|
211 | QUERY="${CONN} -c 'SELECT false' --quiet" |
---|
212 | if eval $QUERY &> /dev/null; |
---|
213 | then |
---|
214 | echo " Fehler: Eingabetabelle ${tables[$x]} existiert nicht." |
---|
215 | else |
---|
216 | echo " Fehler: Verbindung zum Server konnte nicht hergestellt werden!" |
---|
217 | echo " Bitte Verbindungseinstellungen ÃŒberprÃŒfen." |
---|
218 | fi |
---|
219 | exit 0 |
---|
220 | fi |
---|
221 | |
---|
222 | #### PROZESSIERUNG #### |
---|
223 | |
---|
224 | |
---|
225 | echo "Geometrie-Layer: ${tables[$x]}, Clipping-Layer: ${cells[$x]}, aux fields: ${auxfields[$x]}" |
---|
226 | time $CONN -c "DROP TABLE IF EXISTS temp0; |
---|
227 | SELECT ${auxfields[$x]} (ST_Dump(ST_Intersection(rlp.wkb_geometry, t.wkb_geometry))).geom AS wkb_geometry, t.widmung |
---|
228 | INTO temp0 |
---|
229 | FROM ${tables[$x]} t |
---|
230 | INNER JOIN ${cells[$x]} rlp |
---|
231 | ON rlp.wkb_geometry && t.wkb_geometry |
---|
232 | WHERE ST_Intersects( rlp.wkb_geometry, t.wkb_geometry); |
---|
233 | DELETE FROM ${tables[$x]} ; |
---|
234 | INSERT INTO ${tables[$x]} (${auxfields[$x]} wkb_geometry, widmung) SELECT ${auxfields[$x]} wkb_geometry, widmung FROM temp0 WHERE ST_GeometryType( wkb_geometry ) = '${geomtype[$x]}';" |
---|
235 | |
---|
236 | done |
---|