-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure_03_v.state_veg_map_2021.sql
319 lines (287 loc) · 7.7 KB
/
configure_03_v.state_veg_map_2021.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* can't run these concurrently. Do each query as a separate transaction as some occupy a lot of memory */
DROP TABLE IF EXISTS viridarii.state_veg_maps_2021 CASCADE
;
CREATE TABLE viridarii.state_veg_maps_2021 (LIKE
tests.hunterupper_svm_v1_0_pct_e_4894 INCLUDING ALL)
;
ALTER TABLE viridarii.state_veg_maps_2021
DROP COLUMN shape_length,
DROP COLUMN shape_area
;
INSERT INTO viridarii.state_veg_maps_2021 (
mapsource,
pctid,
pctname,
vegetationclass,
vegetationformation,
geom)
SELECT
'centtable_svm_v1p0_pct_e_4778' AS mapsource,
pctid,
pctname,
vegetationclass,
vegetationformation,
geom
FROM tests.centtable_svm_v1p0_pct_e_4778_sbdvd
;
-- INSERT 0 2248705 Query returned successfully in 2 min 55 secs.
INSERT INTO viridarii.state_veg_maps_2021 (
mapsource,
pctid,
pctname,
vegetationclass,
vegetationformation,
geom)
SELECT
'sydneymetroarea_v3_1_2016_e_4489',
pctid,
pctname,
stateclass,
stateform,
geom
FROM tests.sydneymetroarea_v3_1_2016_e_4489_sbdvd
;
-- INSERT 0 194030 Query returned successfully in 18 secs 928 msec.
INSERT INTO viridarii.state_veg_maps_2021 AS x (
mapsource,
pctid,
pctname,
vegetationclass,
vegetationformation,
geom)
SELECT
'western_svm_v1_0_pct_e_4492',
pctid,
pctname,
vegetationclass,
vegetationformation,
geom AS geom
FROM tests.western_svm_v1_0_pct_e_4492_sbdvd
;
-- -- INSERT 0 7586816 Query returned successfully in 5 min 54 secs.
INSERT INTO viridarii.state_veg_maps_2021 (
mapsource,
pctid,
pctname,
vegetationclass,
vegetationformation,
geom)
SELECT
'brg_namoi_svm_v1p3_pct_e_4467' AS mapsource,
pctid,
pctname,
class,
formation,
geom
FROM tests.brg_namoi_svm_v1p3_pct_e_4467_sbdvd
;
-- INSERT 0 1892264 Query returned successfully in 1 min 20 secs.
/*** End of blind inserts ***/
CREATE INDEX state_veg_maps_2021_gidx
ON viridarii.state_veg_maps_2021
USING GIST(geom)
;
-- CREATE INDEX Query returned successfully in 2 min 24 secs.
/*** ***/
DROP TABLE IF EXISTS tests.state_veg_maps_2021_temp_mask CASCADE
;
CREATE TABLE tests.state_veg_maps_2021_temp_mask AS
SELECT
a.id,
ST_Multi(ST_CollectionExtract(ST_Union(ST_Intersection(a.geom, b.geom)),3))::geometry(MultiPolygon, 7855) AS geom
FROM tests.centwestlach_svm_v1p4_pct_e_4468_sbdvd AS a
JOIN viridarii.state_veg_maps_2021 AS b
ON ST_Intersects(a.geom, b.geom)
GROUP BY a.id
;
-- SELECT 179036 Query returned successfully in 17 min 32 secs.
CREATE INDEX state_veg_maps_2021_temp_mask_gidx
ON tests.state_veg_maps_2021_temp_mask
USING GIST(geom)
;
-- CREATE INDEX Query returned successfully in 1 secs 721 msec.
CREATE INDEX state_veg_maps_2021_temp_mask_idx
ON tests.state_veg_maps_2021_temp_mask(id)
;
-- CREATE INDEX Query returned successfully in 252 msec.
INSERT INTO viridarii.state_veg_maps_2021 (
mapsource,
pctid,
pctname,
vegetationclass,
vegetationformation,
geom)
WITH clippers AS (
SELECT v.id,
ST_Union(v.geom) AS geom
FROM tests.centwestlach_svm_v1p4_pct_e_4468_sbdvd AS c
JOIN tests.state_veg_maps_2021_temp_mask AS v
ON ST_Intersects(c.geom, v.geom)
GROUP BY v.id
)
SELECT 'centwestlach_svm_v1p4_pct_e_4468' AS mapsource,
c.pctid,
c.pctname,
c.class,
c.formation,
ST_CollectionExtract(ST_Multi(ST_Difference(c.geom, vu.geom)),3)::geometry(MultiPolygon, 7855) AS geom
FROM tests.centwestlach_svm_v1p4_pct_e_4468_sbdvd AS c
JOIN clippers AS vu
USING (id)
UNION ALL
SELECT 'centwestlach_svm_v1p4_pct_e_4468' AS mapsource,
c.pctid,
c.pctname,
c.class,
c.formation,
c.geom
FROM tests.centwestlach_svm_v1p4_pct_e_4468_sbdvd AS c
LEFT JOIN clippers AS vu
ON vu.id = c.id
WHERE vu.id IS NULL
;
-- INSERT 0 1298198 Query returned successfully in 50 min 12 secs.
/*** ***/
DROP TABLE IF EXISTS tests.state_veg_maps_2021_temp_mask CASCADE
;
CREATE TABLE tests.state_veg_maps_2021_temp_mask AS
SELECT
a.id,
ST_Multi(ST_CollectionExtract(ST_Union(ST_Intersection(a.geom, b.geom)),3))::geometry(MultiPolygon, 7855) AS geom
FROM tests.hunterupper_svm_v1_0_pct_e_4894_sbdvd AS a
JOIN viridarii.state_veg_maps_2021 AS b
ON ST_Intersects(a.geom, b.geom)
GROUP BY a.id
;
-- SELECT 35153 Query returned successfully in 15 min 7 secs.
CREATE INDEX state_veg_maps_2021_temp_mask_gidx
ON tests.state_veg_maps_2021_temp_mask
USING GIST(geom)
;
-- CREATE INDEX Query returned successfully in 1 secs 721 msec.
CREATE INDEX state_veg_maps_2021_temp_mask_idx
ON tests.state_veg_maps_2021_temp_mask(id)
;
-- CREATE INDEX Query returned successfully in 252 msec.
INSERT INTO viridarii.state_veg_maps_2021 (
mapsource,
pctid,
pctname,
vegetationclass,
vegetationformation,
geom)
WITH clippers AS (
SELECT v.id,
ST_Union(v.geom) AS geom
FROM tests.hunterupper_svm_v1_0_pct_e_4894_sbdvd AS c
JOIN tests.state_veg_maps_2021_temp_mask AS v
ON ST_Intersects(c.geom, v.geom)
GROUP BY v.id
)
SELECT 'hunterupper_svm_v1_0_pct_e_4894' AS mapsource,
c.pctid,
c.pctname,
c.vegetationclass,
c.vegetationformation,
ST_CollectionExtract(ST_Multi(ST_Difference(c.geom, vu.geom)),3)::geometry(MultiPolygon, 7855) AS geom
FROM tests.hunterupper_svm_v1_0_pct_e_4894_sbdvd AS c
JOIN clippers AS vu
USING (id)
UNION ALL
SELECT 'hunterupper_svm_v1_0_pct_e_4894' AS mapsource,
c.pctid,
c.pctname,
c.vegetationclass,
c.vegetationformation,
c.geom
FROM tests.hunterupper_svm_v1_0_pct_e_4894_sbdvd AS c
LEFT JOIN clippers AS vu
ON vu.id = c.id
WHERE vu.id IS NULL
;
-- INSERT 0 516202 Query returned successfully in 26 min 20 secs.
/*** ***/
DROP TABLE IF EXISTS tests.state_veg_maps_2021_temp_mask CASCADE
;
CREATE TABLE tests.state_veg_maps_2021_temp_mask AS
SELECT
a.id,
ST_Multi(ST_CollectionExtract(ST_Union(ST_Intersection(a.geom, b.geom)),3))::geometry(MultiPolygon, 7855) AS geom
FROM tests.riverina_v1p2_quickview_sbdvd AS a
JOIN viridarii.state_veg_maps_2021 AS b
ON ST_Intersects(a.geom, b.geom)
GROUP BY a.id
;
-- SELECT 23141 Query returned successfully in 50 secs 823 msec.
CREATE INDEX state_veg_maps_2021_temp_mask_gidx
ON tests.state_veg_maps_2021_temp_mask
USING GIST(geom)
;
-- CREATE INDEX Query returned successfully in 1 secs 721 msec.
CREATE INDEX state_veg_maps_2021_temp_mask_idx
ON tests.state_veg_maps_2021_temp_mask(id)
;
-- CREATE INDEX Query returned successfully in 252 msec.
INSERT INTO viridarii.state_veg_maps_2021 (
mapsource,
pctid,
pctname,
vegetationclass,
vegetationformation,
geom)
WITH clippers AS (
SELECT v.id,
ST_Union(v.geom) AS geom
FROM tests.riverina_v1p2_quickview_sbdvd AS c
JOIN tests.state_veg_maps_2021_temp_mask AS v
ON ST_Intersects(c.geom, v.geom)
GROUP BY v.id
)
SELECT 'riverina_v1p2_quickview' AS mapsource,
c.pctid,
c.pctname,
c.vegetationclass,
c.vegetationformation,
ST_CollectionExtract(ST_Multi(ST_Difference(c.geom, vu.geom)),3)::geometry(MultiPolygon, 7855) AS geom
FROM tests.riverina_v1p2_quickview_sbdvd AS c
JOIN clippers AS vu
USING (id)
UNION ALL
SELECT 'riverina_v1p2_quickview' AS mapsource,
c.pctid,
c.pctname,
c.vegetationclass,
c.vegetationformation,
c.geom
FROM tests.riverina_v1p2_quickview_sbdvd AS c
LEFT JOIN clippers AS vu
ON vu.id = c.id
WHERE vu.id IS NULL
;
-- INSERT 0 2272688 Query returned successfully in 11 min 45 secs.
DELETE
FROM viridarii.state_veg_maps_2021
WHERE ST_Area(geom) < 1
OR geom IS NULL
;
-- DELETE 228609 Query returned successfully in 2 min 25 sec.
UPDATE viridarii.state_veg_maps_2021
SET geom = ST_MakeValid(geom)
WHERE NOT ST_IsValid(geom)
;
-- UPDATE 0 Query returned successfully in 9 min 16 secs.
VACUUM ANALYZE viridarii.state_veg_maps_2021
;
-- VACUUM Query returned successfully in 26 secs 404 msec.
CLUSTER viridarii.state_veg_maps_2021
USING state_veg_maps_2021_gidx
;
-- CLUSTER Query returned successfully in 24 min 22 secs.
DO
$do$
BEGIN
EXECUTE format($$COMMENT ON TABLE viridarii.state_veg_maps_2021 IS 'Table created date: %s'$$, LOCALTIMESTAMP);
END
$do$
;
/*** ***/