/
pgh_hgm--2.2.4.sql
11535 lines (8856 loc) · 328 KB
/
pgh_hgm--2.2.4.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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2023
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
REQUIREMENTS
- Postgresql version 14
- PostGIS version 3+
- PostGIS Raster version 3+
- PgHydro version 6.6 (of 23 aug 2022)
- PgH_Raster version 6.6 (of 30 jun 2023)
Copy to ...\PostgreSQL\14\share\extension
REPOSITORIES
https://github.com/pghydro/pghydro
https://github.com/HGE-IPH/pgh_hgm
Authors:
Mino V Sorribas, mino.sorribas@gmail.com
Fernando M Fan, fernando.fan@ufrgs.br
Stefany G Lima, stefglima@gmail.com
Maria Eduarda P Alves, duda.epa@gmail.com
Alexandre de Amorim Teixeira, pghydro.project@gmail.com
*/
---------------------------------------------------------------------------------
--PGH_HGM: PgHydro Hydrological Geomorphology Calculations Extension - v.2.2.4 (2024.02.19)
---------------------------------------------------------------------------------
-------------------------------------
-- DROP AND CREATE SCHEMA
-------------------------------------
DROP SCHEMA IF EXISTS pgh_hgm CASCADE;
CREATE SCHEMA pgh_hgm;
CREATE OR REPLACE FUNCTION pgh_hgm.pghfn_tables_initialize()
RETURNS CHARACTER VARYING AS
$BODY$
/*
PREPARE PGH_HGM INTEL TABLE WITH EXISTING ATTRIBUTES FROM PGHYDRO
*/
BEGIN
-- TRUNCATE TABLES
TRUNCATE TABLE pgh_hgm.pghft_hydro_intel;
TRUNCATE TABLE pgh_hgm.pghft_drn_elevationprofile;
TRUNCATE TABLE pgh_hgm.pghft_upn_elevationprofile;
-- FIRST FILL DRN_PK, DRA_PK AND WTC_PK COLUMNS
INSERT INTO pgh_hgm.pghft_hydro_intel(
hig_drn_pk,
hig_dra_pk,
hig_wtc_pk,
hig_drn_strahler,
hig_dra_area_,
hig_upa_area_,
hig_drn_length_,
hig_dra_area_km2,
hig_upa_area_km2,
hig_drn_length_km
)
SELECT
drn.drn_pk,
dra.dra_pk,
drn.drn_wtc_pk,
hin.hin_strahler AS hig_drn_strahler,
-- user-defined pghydro units
dra.dra_gm_area AS hig_dra_area_,
drn.drn_nu_upstreamarea AS hig_upa_area_,
drn.drn_gm_length AS hig_drn_length_,
-- assuming km and km2
dra.dra_gm_area AS hig_dra_area_km2,
drn.drn_nu_upstreamarea AS hig_upa_area_km2,
drn.drn_gm_length AS hig_drn_length_km
FROM pghydro.pghft_drainage_area dra
INNER JOIN pghydro.pghft_drainage_line drn ON drn.drn_dra_pk = dra.dra_pk
INNER JOIN pghydro.pghft_hydro_intel hin ON hin.hin_drn_pk = drn.drn_pk
ORDER BY drn.drn_pk ASC;
RAISE NOTICE ' - inherited attributes from pghydro into pgh_hgm.pghft_hydro_intel';
-- CREATE MAIN INDEXES
DROP INDEX IF EXISTS pgh_hgm.hig_drn_idx;
DROP INDEX IF EXISTS pgh_hgm.hig_dra_idx;
DROP INDEX IF EXISTS pgh_hgm.hig_drn_dra_idx;
CREATE INDEX hig_drn_idx ON pgh_hgm.pghft_hydro_intel USING btree(hig_drn_pk);
CREATE INDEX hig_dra_idx ON pgh_hgm.pghft_hydro_intel USING btree(hig_dra_pk);
CREATE INDEX hig_drn_dra_idx ON pgh_hgm.pghft_hydro_intel USING btree(hig_drn_pk,hig_dra_pk);
RAISE NOTICE ' - primary key indexes included in pgh_hgm.pghft_hydro_intel';
-- CREATE AUXILIARY INDEXES
DROP INDEX IF EXISTS pgh_hgm.hig_wtc_idx;
DROP INDEX IF EXISTS pgh_hgm.hig_dra_wtc_idx;
DROP INDEX IF EXISTS pgh_hgm.hig_dra_wtc_strahler_idx;
CREATE INDEX hig_wtc_idx ON pgh_hgm.pghft_hydro_intel USING btree(hig_wtc_pk);
CREATE INDEX hig_dra_wtc_idx ON pgh_hgm.pghft_hydro_intel USING btree(hig_dra_pk,hig_wtc_pk);
CREATE INDEX hig_dra_wtc_strahler_idx ON pgh_hgm.pghft_hydro_intel USING btree(hig_dra_pk,hig_wtc_pk,hig_drn_strahler);
-- CREATE ELEVATION PROFILE INDEXES (not really useful yet)
DROP INDEX IF EXISTS pgh_hgm.elpdrn_dra_idx;
DROP INDEX IF EXISTS pgh_hgm.elpupn_dra_idx;
CREATE INDEX elpdrn_dra_idx ON pgh_hgm.pghft_drn_elevationprofile USING btree(dra_pk);
CREATE INDEX elpupn_dra_idx ON pgh_hgm.pghft_upn_elevationprofile USING btree(dra_pk);
-- CREATE INDEX ON WATERCOURSEORDER
-- CALCULATE UPSTREAM MAIN RIVER LENGTH BASED ON WTC/DRN ATTRIBUTES
-- WHEN DRN IN WATERCOURSE ORDER = 1
UPDATE pgh_hgm.pghft_hydro_intel
SET
hig_upn_length_ = a.hig_upn_length_,
hig_upn_length_km = a.hig_upn_length_km
FROM (
SELECT
hig_drn_pk AS drn_pk_,
wtc.wtc_gm_length - drn.drn_nu_distancetosea AS hig_upn_length_,
wtc.wtc_gm_length - drn.drn_nu_distancetosea AS hig_upn_length_km --assuming km2
FROM pgh_hgm.pghft_hydro_intel hig
INNER JOIN pghydro.pghft_drainage_line drn ON drn.drn_pk = hig.hig_drn_pk
INNER JOIN pghydro.pghft_watercourse wtc ON wtc.wtc_pk = drn.drn_wtc_pk
WHERE wtc.wtc_nu_pfafstetterwatercoursecodeorder = 1) a
WHERE hig_drn_pk = a.drn_pk_;
-- WHEN DRN IN WATERCOURSE ORDER > 1
UPDATE pgh_hgm.pghft_hydro_intel
SET
hig_upn_length_ = a.hig_upn_length_,
hig_upn_length_km = a.hig_upn_length_km
FROM (
SELECT
hig_drn_pk AS drn_pk_,
wtc.wtc_gm_length - drn.drn_nu_distancetowatercourse AS hig_upn_length_,
wtc.wtc_gm_length - drn.drn_nu_distancetowatercourse AS hig_upn_length_km --assuming km2
FROM pgh_hgm.pghft_hydro_intel hig
INNER JOIN pghydro.pghft_drainage_line drn ON drn.drn_pk = hig.hig_drn_pk
INNER JOIN pghydro.pghft_watercourse wtc ON wtc.wtc_pk = drn.drn_wtc_pk
WHERE wtc.wtc_nu_pfafstetterwatercoursecodeorder > 1 ) a
WHERE hig_drn_pk = a.drn_pk_;
RETURN 'OK';
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
-----------------------------------------
-- CREATE TABLES
-----------------------------------------
-- CREATE AUXILIARY TABLE FOR TEMPORARY 'LOCAL REACH ELEVATION PROFILE'
DROP TABLE IF EXISTS pgh_hgm.pghft_drn_elevationprofile;
CREATE TABLE pgh_hgm.pghft_drn_elevationprofile(
dra_pk integer,
xy integer,
z double precision,
gm geometry --NOTE: not really needed
);
-- CREATE AUXILIARY TABLE FOR TEMPORARY 'MAIN-STREAM ELEVATION PROFILE'
DROP TABLE IF EXISTS pgh_hgm.pghft_upn_elevationprofile;
CREATE TABLE pgh_hgm.pghft_upn_elevationprofile(
dra_pk integer,
xy integer,
z double precision,
gm geometry --NOTE: not really needed
);
-- CREATE SEQUENCE FOR PGH_HGM INTEL TABLE
DROP SEQUENCE IF EXISTS pgh_hgm.hig_pk_seq CASCADE;
CREATE SEQUENCE pgh_hgm.hig_pk_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
-- CREATE PGH_HGM INTEL TABLE
DROP TABLE IF EXISTS pgh_hgm.pghft_hydro_intel;
CREATE TABLE pgh_hgm.pghft_hydro_intel(
----------------------------------------------
-- PRIMARY AND AUXILIARY KEYS
----------------------------------------------
hig_pk integer DEFAULT nextval('pgh_hgm.hig_pk_seq'::regclass),
hig_drn_pk integer,
hig_dra_pk integer,
hig_wtc_pk integer, -- watercourses, helpful as 'null' is coastline
hig_drn_strahler integer, -- helpful to get headwaters
--hig_drn_gm geometry, -- easy outputs.
----------------------------------------------
-- DEM BASED
--------------------------------------------
-- depends on elevation profile
-- stream elevation
hig_drn_elevation_avg double precision,
hig_drn_elevation_max double precision,
hig_drn_elevation_min double precision,
-- stream elevation drop
hig_drn_elevationdrop_maxmin double precision,
hig_drn_elevationdrop_s1585 double precision,
hig_drn_elevationdrop_pipf double precision,
hig_drn_elevationdrop_z1585 double precision,
hig_drn_elevationdrop_harmonic double precision,
hig_drn_elevationdrop_weighted double precision,
hig_drn_elevationdrop_linreg double precision,
-- stream slopes
hig_drn_slope_maxmin double precision,
hig_drn_slope_s1585 double precision,
hig_drn_slope_pipf double precision,
hig_drn_slope_z1585 double precision,
hig_drn_slope_harmonic double precision,
hig_drn_slope_weighted double precision,
hig_drn_slope_linreg double precision,
----------------------------------------------
-- GEOMETRY AND HYDROGEOMORPHOLOGY
----------------------------------------------
---------------------------------------------
--- LOCAL CATCHMENT
---------------------------------------------
-- local catchment pghydro attributes
hig_dra_area_ double precision, -- pghydro input units
hig_dra_area_km2 double precision, -- pgh_hgm standard
-- "pghydro eligible" local cathcment attributes...
hig_dra_perimeter_ double precision, -- pghydro input units
hig_dra_perimeter_km double precision,
-- new local cathcment attributes...
hig_dra_axislength double precision, -- axial length
hig_dra_circularity double precision, -- circularity
hig_dra_compacity double precision, -- compacity
hig_dra_shapefactor double precision, -- shape factor
hig_dra_formfactor double precision, -- form factor
-- drainage...
hig_drn_sinuosity double precision, -- sinuosity, actually from drainage
-- more local cathcment attributes (requires DEM)
-- calculated using internal call to .pghfn_drn_drn_elevation_profile
hig_dra_reliefratio double precision, -- relief ratio
hig_dra_reachgradient double precision, -- reach gradient
-- catchment elevation stats
hig_dra_elevation_avg double precision,
hig_dra_elevation_max double precision,
hig_dra_elevation_min double precision,
hig_dra_elevationdrop_m double precision, -- maxmin based
-- "strange" area attributes for local catchment
hig_dra_drainagedensity double precision, -- drainage density
hig_dra_hydrodensity double precision, -- hydro density
hig_dra_avglengthoverlandflow double precision, -- average length of overflow land
----------------------------------------------
-- LOCAL STREAM/DRAINAGE HYDRAULICS
----------------------------------------------
-- "pghydro eligible" local drainage attributes...
hig_drn_length_ double precision, -- pghydro input units
hig_drn_length_km double precision, -- pgh_hgm standard
-- depth and width geomorphological relations
hig_drn_depth_m double precision,
hig_drn_width_m double precision,
-- stream drop, slope and manning roughness
hig_drn_elevationdrop_m double precision, -- we assume: maxmin method
hig_drn_slope_adim double precision, -- we assume: maxmin method
hig_drn_manning_n double precision,
-- wave-travel "manning" hydraulics (velocities, celerities, travel)
hig_drn_velmann double precision,
hig_drn_celmann double precision,
hig_drn_trlmann double precision, -- minutes
hig_drn_velmann_lr double precision,
hig_drn_celmann_lr double precision,
hig_drn_trlmann_lr double precision,
-- wave travel: dynamic wave
hig_drn_celdyna double precision,
hig_drn_trldyna double precision,
---------------------------------------------
--- UPSTREAM AREA
---------------------------------------------
-- upstream area pghydro attributes
hig_upa_area_ double precision, -- input unit
hig_upa_area_km2 double precision, -- km2
-- "pghydro eligible" upstream geometry attributes...
hig_upa_perimeter_ double precision, -- input unit
hig_upa_perimeter_km double precision, -- km
-- new upstream area attributes
hig_upa_drainagedensity double precision, -- drainage density
hig_upa_hydrodensity double precision, -- hydro density
hig_upa_avglengthoverlandflow double precision, -- average length of overflow land
hig_upa_totaldrainagelength double precision, -- sum of lengths upstream
-- "catchment attributes" applied to upstream area scale
hig_upa_axislength double precision, -- axial length
hig_upa_circularity double precision, -- circularity
hig_upa_compacity double precision, -- compacity
hig_upa_shapefactor double precision, -- shape factor
hig_upa_formfactor double precision, -- form factor
-- drainage...
hig_upn_sinuosity double precision, -- sinuosity
-- MS: catchment elevation stats
hig_upa_elevation_avg double precision,
hig_upa_elevation_max double precision,
hig_upa_elevation_min double precision,
hig_upa_elevationdrop_m double precision, -- maxmin based
-- MS: dem-based stats
hig_upa_reliefratio double precision, -- relief ratio
hig_upa_reachgradient double precision, -- reach gradient
----------------------------------------------
-- TIME OF CONCENTRATION
----------------------------------------------
-- local drainage/area
-- note: dra attribute
hig_dra_tc_kirpich double precision,
hig_dra_tc_dooge double precision,
hig_dra_tc_carter double precision,
hig_dra_tc_armycorps double precision,
hig_dra_tc_wattchow double precision,
hig_dra_tc_kirpicha double precision, -- kirpich's based on dra/upa _elevation_drop_m
hig_dra_tc_georgeribeiro double precision,
hig_dra_tc_pasini double precision,
hig_dra_tc_ventura double precision,
hig_dra_tc_dnosk1 double precision,
-- upstream area/main river (upa)
hig_upa_tc_kirpich double precision,
hig_upa_tc_dooge double precision,
hig_upa_tc_carter double precision,
hig_upa_tc_armycorps double precision,
hig_upa_tc_wattchow double precision,
hig_upa_tc_kirpicha double precision, -- kirpich's based on dra/upa _elevation_drop_m
hig_upa_tc_georgeribeiro double precision,
hig_upa_tc_pasini double precision,
hig_upa_tc_ventura double precision,
hig_upa_tc_dnosk1 double precision,
----------------------------------------------
-- UPSTREAM MAIN-RIVER ATTRIBUTES
----------------------------------------------
-- "main-river" (upn)
hig_upn_elevation_avg double precision,
hig_upn_elevation_max double precision,
hig_upn_elevation_min double precision,
hig_upn_length_ double precision, -- pghydro input units
hig_upn_length_km double precision,
hig_upn_elevationdrop_m double precision, -- maxmin based
hig_upn_slope_adim double precision, -- maxmin based
--... required for time of concentration
-- stream slopes
hig_upn_slope_maxmin double precision,
hig_upn_slope_s1585 double precision,
hig_upn_slope_pipf double precision,
hig_upn_slope_z1585 double precision,
hig_upn_slope_harmonic double precision,
hig_upn_slope_weighted double precision,
hig_upn_slope_linreg double precision,
-- elevation profile drop
hig_upn_elevationdrop_maxmin double precision,
hig_upn_elevationdrop_s1585 double precision,
hig_upn_elevationdrop_pipf double precision,
hig_upn_elevationdrop_z1585 double precision,
hig_upn_elevationdrop_harmonic double precision,
hig_upn_elevationdrop_weighted double precision,
hig_upn_elevationdrop_linreg double precision,
----------------------------------------------
-- JOBSON'S SCALAR TRANSPORT/TRAVEL TIME MODEL FOR DRAINAGE
----------------------------------------------
-- inputs to jobson
hig_drn_annual_flow double precision,
hig_drn_event_flow double precision,
-- jobson outputs
hig_drn_jobson_tpeak double precision,
hig_drn_jobson_tlead double precision,
hig_drn_jobson_tpeak_shortest double precision,
hig_drn_jobson_tlead_shortest double precision,
----------------------------------------------
-- temporary merged-upstream geometries
----------------------------------------------
-- main river upstream (upn) and merged upstream area (polygon)
hig_upn_gm geometry,
hig_upa_gm geometry,
----------------------------------------------
-- experimental: reservoirs features
----------------------------------------------
-- input table columns
hig_drn_reservoir_depth_m double precision,
hig_drn_reservoir_length_m double precision,
-- outputs (pgh_hgm.pghfn_drn_wavetravel_reservoir)
hig_drn_reservoir_celwave double precision,
hig_drn_reservoir_trlwave double precision,
------------------------------------------------
-- additional methods for axis length and related attributes
------------------------------------------------
hig_dra_axislength_schumm double precision, -- axis length
hig_dra_shapefactor_schumm double precision, -- shape factor
hig_dra_formfactor_schumm double precision, -- form factor
hig_dra_reliefratio_schumm double precision, -- relief ratio
hig_dra_axislength_ring double precision, -- axis length
hig_dra_shapefactor_ring double precision, -- shape factor
hig_dra_formfactor_ring double precision, -- form factor
hig_dra_reliefratio_ring double precision, -- relief ratio
hig_dra_axislength_river double precision, -- axis length
hig_dra_shapefactor_river double precision, -- shape factor
hig_dra_formfactor_river double precision, -- form factor
hig_dra_reliefratio_river double precision, -- relief ratio
hig_upa_axislength_schumm double precision, -- axis length
hig_upa_shapefactor_schumm double precision, -- shape factor
hig_upa_formfactor_schumm double precision, -- form factor
hig_upa_reliefratio_schumm double precision, -- relief ratio
hig_upa_axislength_ring double precision, -- axis length
hig_upa_shapefactor_ring double precision, -- shape factor
hig_upa_formfactor_ring double precision, -- form factor
hig_upa_reliefratio_ring double precision, -- relief ratio
hig_upa_axislength_river double precision, -- axis length
hig_upa_shapefactor_river double precision, -- shape factor
hig_upa_formfactor_river double precision, -- form factor
hig_upa_reliefratio_river double precision -- relief ratio
);
-- FILL TABLES WITH DATA FROM PGHYDRO SCHEMA
-- SELECT pgh_hgm.pghfn_tables_initialize();
-- COMMANDS FOR VACUUM
--VACUUM(FULL, ANALYZE) pgh_hgm.pghft_hydro_intel;
--VACUUM(FULL, ANALYZE) pgh_hgm.pghft_drn_elevationprofile;
--VACUUM(FULL, ANALYZE) pgh_hgm.pghft_upn_elevationprofile;
-------------------------------------
--CREATE FUNCTIONS
-------------------------------------
CREATE OR REPLACE FUNCTION pgh_hgm.pghfn_drn_elevationprofile(
IN dra_pk_ integer)
RETURNS TABLE(dra_pk integer, xy integer, z double precision, gm geometry) AS
$BODY$
/*
QUERY DRAINAGE LINE ELEVATION PROFILE
USING DRA_PK
calls:
pgh_raster.pghfn_elevation_profile() -> returns (xy integer, z double precision, gm geometry)
*/
DECLARE
srid_dem integer;
BEGIN
-- get DEM srid
SELECT srid INTO srid_dem
FROM public.raster_columns
WHERE r_table_schema = 'pgh_raster' AND r_table_name = 'pghrt_elevation';
-- main query
RETURN
QUERY
WITH raw_elevprof AS (
SELECT
dra_pk_ AS dra_pk,
a.xy,
a.z,
a.gm,
ROW_NUMBER() OVER( PARTITION BY a.xy) xy_idx
FROM (
-- CALL PGH_RASTER
SELECT
(pgh_raster.pghfn_elevation_profile(line_gm)).* -- original spacing using pgh_raster
-- (pgh_raster.pghfn_elevation_profile(line_gm,60)).* -- 60 m spacing using pgh_raster
--(pgh_hgm.pghfn_geom_elevationprofile(line_gm)).* -- original spacing using pgh_hgm standalone function
FROM
(
-- PREPARE DRAINAGE POINTS (FROM DRAINAGE LINE) TO PGH_RASTER
SELECT
ST_TRANSFORM( (ST_DUMP(drn_gm)).geom, srid_dem) AS line_gm
FROM pghydro.pghft_drainage_area dra
INNER JOIN pghydro.pghft_drainage_line drn ON dra.dra_pk = drn.drn_dra_pk
WHERE dra.dra_pk = dra_pk_
) a
) a
)
-- FILTER DUPLICATES
SELECT a.dra_pk, a.xy, a.z, a.gm FROM raw_elevprof a WHERE a.xy_idx = 1;
RETURN;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION pgh_hgm.pghfn_dra_elevations(
IN dra_pk_ integer)
RETURNS TABLE(dra_pk integer, pixels double precision) AS
$BODY$
/*
QUERY LOCAL CATCHMENT AREA - ELEVATIONS FROM DEM
BY CLIPPING 'dra_gm' with 'pgh_raster.elevation'
USING DRA_PK
*/
DECLARE
srid_dem integer;
BEGIN
-- get DEM srid
SELECT srid INTO srid_dem
FROM public.raster_columns
WHERE r_table_schema = 'pgh_raster' AND r_table_name = 'pghrt_elevation';
-- query
RETURN
QUERY
SELECT
dra_pk_ as dra_pk,
a.pixels
FROM (
SELECT
UNNEST((st_dumpvalues(rclip)).valarray) as pixels
FROM (
--- CLIP RASTER IN POLYGON INTERSECTION
SELECT
ST_CLIP(rast, g.dra_gm_srid_dem, -9999) as rclip
FROM pgh_raster.pghrt_elevation r
INNER JOIN
(
-- JOIN WITH CATCHMENT
SELECT
ST_TRANSFORM(dra_gm, srid_dem) AS dra_gm_srid_dem
FROM pghydro.pghft_drainage_area dra
WHERE dra.dra_pk = dra_pk_
) g
-- SPATIAL JOIN
ON ST_Intersects(r.rast, g.dra_gm_srid_dem)
) a
) a
WHERE a.pixels IS NOT NULL;
RETURN;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE VIEW pgh_hgm.geoft_bho_hgm AS
SELECT
hig_pk, hig_drn_pk, hig_dra_pk, hig_wtc_pk, hig_drn_strahler,
hig_drn_elevation_avg, hig_drn_elevation_max, hig_drn_elevation_min, hig_drn_elevationdrop_maxmin, hig_drn_elevationdrop_s1585, hig_drn_elevationdrop_pipf, hig_drn_elevationdrop_z1585, hig_drn_elevationdrop_harmonic, hig_drn_elevationdrop_weighted, hig_drn_elevationdrop_linreg, hig_drn_slope_maxmin, hig_drn_slope_s1585, hig_drn_slope_pipf, hig_drn_slope_z1585, hig_drn_slope_harmonic, hig_drn_slope_weighted, hig_drn_slope_linreg,
hig_dra_area_, hig_dra_area_km2, hig_dra_perimeter_, hig_dra_perimeter_km, hig_dra_axislength, hig_dra_circularity, hig_dra_compacity, hig_dra_shapefactor, hig_dra_formfactor, hig_drn_sinuosity, hig_dra_reliefratio, hig_dra_reachgradient, hig_dra_elevation_avg, hig_dra_elevation_max, hig_dra_elevation_min, hig_dra_elevationdrop_m, hig_dra_drainagedensity, hig_dra_hydrodensity, hig_dra_avglengthoverlandflow,
hig_drn_length_, hig_drn_length_km, hig_drn_depth_m, hig_drn_width_m, hig_drn_elevationdrop_m, hig_drn_slope_adim, hig_drn_manning_n, hig_drn_velmann, hig_drn_celmann, hig_drn_trlmann, hig_drn_velmann_lr, hig_drn_celmann_lr, hig_drn_trlmann_lr, hig_drn_celdyna, hig_drn_trldyna,
hig_upa_area_, hig_upa_area_km2, hig_upa_perimeter_, hig_upa_perimeter_km, hig_upa_drainagedensity, hig_upa_hydrodensity, hig_upa_avglengthoverlandflow, hig_upa_totaldrainagelength, hig_upa_axislength, hig_upa_circularity, hig_upa_compacity, hig_upa_shapefactor, hig_upa_formfactor, hig_upn_sinuosity, hig_upa_elevation_avg, hig_upa_elevation_max, hig_upa_elevation_min, hig_upa_elevationdrop_m, hig_upa_reliefratio, hig_upa_reachgradient,
hig_dra_tc_kirpich, hig_dra_tc_dooge, hig_dra_tc_carter, hig_dra_tc_armycorps, hig_dra_tc_wattchow,
hig_dra_tc_kirpicha, hig_dra_tc_georgeribeiro, hig_dra_tc_pasini, hig_dra_tc_ventura, hig_dra_tc_dnosk1,
hig_upa_tc_kirpich, hig_upa_tc_dooge, hig_upa_tc_carter, hig_upa_tc_armycorps, hig_upa_tc_wattchow, hig_upa_tc_kirpicha,
hig_upa_tc_georgeribeiro, hig_upa_tc_pasini, hig_upa_tc_ventura, hig_upa_tc_dnosk1,
hig_upn_elevation_avg, hig_upn_elevation_max, hig_upn_elevation_min, hig_upn_length_, hig_upn_length_km,
hig_upn_elevationdrop_m, hig_upn_slope_adim, hig_upn_slope_maxmin, hig_upn_slope_s1585, hig_upn_slope_pipf, hig_upn_slope_z1585, hig_upn_slope_harmonic, hig_upn_slope_weighted, hig_upn_slope_linreg, hig_upn_elevationdrop_maxmin, hig_upn_elevationdrop_s1585, hig_upn_elevationdrop_pipf, hig_upn_elevationdrop_z1585, hig_upn_elevationdrop_harmonic, hig_upn_elevationdrop_weighted, hig_upn_elevationdrop_linreg,
hig_drn_annual_flow, hig_drn_event_flow, hig_drn_jobson_tpeak, hig_drn_jobson_tlead, hig_drn_jobson_tpeak_shortest, hig_drn_jobson_tlead_shortest,
--hig_upn_gm, hig_upa_gm,
hig_drn_reservoir_depth_m, hig_drn_reservoir_length_m,
hig_drn_reservoir_celwave, hig_drn_reservoir_trlwave,
-- BONUS info
hig_dra_axislength_schumm, hig_dra_shapefactor_schumm, hig_dra_formfactor_schumm, hig_dra_reliefratio_schumm,
hig_dra_axislength_ring, hig_dra_shapefactor_ring, hig_dra_formfactor_ring, hig_dra_reliefratio_ring,
hig_dra_axislength_river, hig_dra_shapefactor_river, hig_dra_formfactor_river, hig_dra_reliefratio_river,
hig_upa_axislength_schumm, hig_upa_shapefactor_schumm, hig_upa_formfactor_schumm, hig_upa_reliefratio_schumm,
hig_upa_axislength_ring, hig_upa_shapefactor_ring, hig_upa_formfactor_ring, hig_upa_reliefratio_ring,
hig_upa_axislength_river, hig_upa_shapefactor_river, hig_upa_formfactor_river, hig_upa_reliefratio_river,
drn_gm -- get drainage geometry
FROM pgh_hgm.pghft_hydro_intel hig
INNER JOIN pghydro.pghft_drainage_line drn ON hig_drn_pk = drn_pk;
CREATE OR REPLACE VIEW pgh_hgm.geoft_bho_hgm_dradrn AS
SELECT
hig_pk, hig_drn_pk, hig_dra_pk, hig_wtc_pk, hig_drn_strahler,
hig_drn_elevation_avg, hig_drn_elevation_max, hig_drn_elevation_min, hig_drn_elevationdrop_maxmin, hig_drn_elevationdrop_s1585, hig_drn_elevationdrop_pipf, hig_drn_elevationdrop_z1585, hig_drn_elevationdrop_harmonic, hig_drn_elevationdrop_weighted, hig_drn_elevationdrop_linreg, hig_drn_slope_maxmin, hig_drn_slope_s1585, hig_drn_slope_pipf, hig_drn_slope_z1585, hig_drn_slope_harmonic, hig_drn_slope_weighted, hig_drn_slope_linreg,
hig_dra_area_, hig_dra_area_km2, hig_dra_perimeter_, hig_dra_perimeter_km, hig_dra_axislength, hig_dra_circularity, hig_dra_compacity, hig_dra_shapefactor, hig_dra_formfactor, hig_drn_sinuosity, hig_dra_reliefratio, hig_dra_reachgradient, hig_dra_elevation_avg, hig_dra_elevation_max, hig_dra_elevation_min, hig_dra_elevationdrop_m, hig_dra_drainagedensity, hig_dra_hydrodensity, hig_dra_avglengthoverlandflow,
hig_drn_length_, hig_drn_length_km, hig_drn_depth_m, hig_drn_width_m, hig_drn_elevationdrop_m, hig_drn_slope_adim, hig_drn_manning_n, hig_drn_velmann, hig_drn_celmann, hig_drn_trlmann, hig_drn_velmann_lr, hig_drn_celmann_lr, hig_drn_trlmann_lr, hig_drn_celdyna, hig_drn_trldyna,
hig_dra_tc_kirpich, hig_dra_tc_dooge, hig_dra_tc_carter, hig_dra_tc_armycorps, hig_dra_tc_wattchow,
hig_dra_tc_kirpicha, hig_dra_tc_georgeribeiro, hig_dra_tc_pasini, hig_dra_tc_ventura, hig_dra_tc_dnosk1,
hig_drn_annual_flow, hig_drn_event_flow, hig_drn_jobson_tpeak, hig_drn_jobson_tlead, hig_drn_jobson_tpeak_shortest, hig_drn_jobson_tlead_shortest,
hig_drn_reservoir_depth_m, hig_drn_reservoir_length_m,
hig_drn_reservoir_celwave, hig_drn_reservoir_trlwave,
-- BONUS info
hig_dra_axislength_schumm, hig_dra_shapefactor_schumm, hig_dra_formfactor_schumm, hig_dra_reliefratio_schumm,
hig_dra_axislength_ring, hig_dra_shapefactor_ring, hig_dra_formfactor_ring, hig_dra_reliefratio_ring,
hig_dra_axislength_river, hig_dra_shapefactor_river, hig_dra_formfactor_river, hig_dra_reliefratio_river,
drn_gm -- get drainage geometry
FROM pgh_hgm.pghft_hydro_intel hig
INNER JOIN pghydro.pghft_drainage_line drn ON hig_drn_pk = drn_pk;
CREATE OR REPLACE VIEW pgh_hgm.geoft_bho_hgm_upaupn AS
SELECT
hig_pk, hig_drn_pk, hig_dra_pk, hig_wtc_pk
hig_upa_area_, hig_upa_area_km2, hig_upa_perimeter_, hig_upa_perimeter_km, hig_upa_drainagedensity, hig_upa_hydrodensity, hig_upa_avglengthoverlandflow, hig_upa_totaldrainagelength, hig_upa_axislength, hig_upa_circularity, hig_upa_compacity, hig_upa_shapefactor, hig_upa_formfactor, hig_upn_sinuosity, hig_upa_elevation_avg, hig_upa_elevation_max, hig_upa_elevation_min, hig_upa_elevationdrop_m, hig_upa_reliefratio, hig_upa_reachgradient,
hig_upa_tc_kirpich, hig_upa_tc_dooge, hig_upa_tc_carter, hig_upa_tc_armycorps, hig_upa_tc_wattchow, hig_upa_tc_kirpicha,
hig_upa_tc_georgeribeiro, hig_upa_tc_pasini, hig_upa_tc_ventura, hig_upa_tc_dnosk1,
hig_upn_elevation_avg, hig_upn_elevation_max, hig_upn_elevation_min, hig_upn_length_, hig_upn_length_km,
hig_upn_elevationdrop_m, hig_upn_slope_adim, hig_upn_slope_maxmin, hig_upn_slope_s1585, hig_upn_slope_pipf, hig_upn_slope_z1585, hig_upn_slope_harmonic, hig_upn_slope_weighted, hig_upn_slope_linreg, hig_upn_elevationdrop_maxmin, hig_upn_elevationdrop_s1585, hig_upn_elevationdrop_pipf, hig_upn_elevationdrop_z1585, hig_upn_elevationdrop_harmonic, hig_upn_elevationdrop_weighted, hig_upn_elevationdrop_linreg,
--hig_upn_gm, hig_upa_gm,
-- BONUS info
hig_upa_axislength_schumm, hig_upa_shapefactor_schumm, hig_upa_formfactor_schumm, hig_upa_reliefratio_schumm,
hig_upa_axislength_ring, hig_upa_shapefactor_ring, hig_upa_formfactor_ring, hig_upa_reliefratio_ring,
hig_upa_axislength_river, hig_upa_shapefactor_river, hig_upa_formfactor_river, hig_upa_reliefratio_river,
drn_gm -- get drainage geometry
FROM pgh_hgm.pghft_hydro_intel hig
INNER JOIN pghydro.pghft_drainage_line drn ON hig_drn_pk = drn_pk;
CREATE OR REPLACE FUNCTION pgh_hgm.pghfn_calculate_dra_avglengthoverlandflow(
srid_area integer,
srid_length integer)
RETURNS character varying AS
$BODY$
/*
CALCULATE LOCAL CATCHMENT - 'AVERAGE LENGTH OF OVERLAND FLOW
*/
DECLARE
time_ timestamp;
i integer;
imin integer;
imax integer;
BEGIN
-- TABLE ROWS REFERENCES
imin := min(hig_dra_pk) FROM pgh_hgm.pghft_hydro_intel;
imax := max(hig_dra_pk) FROM pgh_hgm.pghft_hydro_intel;
RAISE NOTICE 'LOOP SETUP DRA_PK = % - %',imin,imax;
-- DROP AND CREATE INDEXES
-- args: (only_drop, index_drn_dra, index_dra_wtc, index_upa, index_elpdrn, index_elpupn)
PERFORM pgh_hgm.pghfn_utils_index_dropcreate(FALSE, TRUE, TRUE, FALSE, FALSE, FALSE);
--------------------------------------------------------
-- MAIN LOOP - ASSUMES EXISTING DRA_PK FROM IMIN TO IMAX
--------------------------------------------------------
FOR i IN imin..imax LOOP
RAISE NOTICE 'BEGIN OF PROCESS %/%: %', i,imax,timeofday();
------------------------------------------------------
-- CALCULATE/UPDATE ATTRIBUTE
------------------------------------------------------
-- good to gofrom pghydro
UPDATE pgh_hgm.pghft_hydro_intel
SET
hig_dra_avglengthoverlandflow = a.avglengthoverlandflow
FROM (
SELECT
*
FROM
pgh_hgm.pghfn_dra_avglengthoverlandflow(i,1.,1.)
) a
WHERE hig_dra_pk = i AND hig_wtc_pk IS NOT NULL;
-- FINISH
END LOOP;
time_ := timeofday();
RAISE NOTICE 'END OF PROCESS IN : %', time_;
RETURN 'OK';
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION pgh_hgm.pghfn_calculate_dra_axislength(
srid_area integer,
srid_length integer)
RETURNS character varying AS
$BODY$
/*
CALCULATE LOCAL CATCHMENT - AXIS LENGTH
*/
DECLARE
time_ timestamp;
i integer;
imin integer;
imax integer;
BEGIN
-- TABLE ROWS REFERENCES
imin := min(hig_dra_pk) FROM pgh_hgm.pghft_hydro_intel;
imax := max(hig_dra_pk) FROM pgh_hgm.pghft_hydro_intel;
RAISE NOTICE 'LOOP SETUP DRA_PK = % - %',imin,imax;
-- DROP AND CREATE INDEXES
-- args: (only_drop, index_drn_dra, index_dra_wtc, index_upa, index_elpdrn, index_elpupn)
PERFORM pgh_hgm.pghfn_utils_index_dropcreate(FALSE, TRUE, TRUE, FALSE, FALSE, FALSE);
--------------------------------------------------------
-- MAIN LOOP - ASSUMES EXISTING DRA_PK FROM IMIN TO IMAX
--------------------------------------------------------
FOR i IN imin..imax LOOP
RAISE NOTICE 'BEGIN OF PROCESS %/%: %', i,imax,timeofday();
------------------------------------------------------
-- CALCULATE/UPDATE ATTRIBUTE
------------------------------------------------------
UPDATE pgh_hgm.pghft_hydro_intel
SET
hig_dra_axislength = a.axislength
FROM (
SELECT
*
FROM
pgh_hgm.pghfn_dra_axislength(i,srid_length) -- axis length
) a
WHERE hig_dra_pk = i AND hig_wtc_pk IS NOT NULL;
-- FINISH
END LOOP;
time_ := timeofday();
RAISE NOTICE 'END OF PROCESS IN : %', time_;
RETURN 'OK';
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION pgh_hgm.pghfn_calculate_dra_bonus_ring(
srid_area integer,
srid_length integer)
RETURNS character varying AS
$BODY$
/*
CALCULATE LOCAL CATCHMENT - AXIS LENGTH, SHAPEFACTOR, FORMFACTOR, RELIEF RATIO
(XIS LENGTH AS 'MAX DISTANCE IN EXTERIOR RING APPROACH)
*/
DECLARE
time_ timestamp;
i integer;
imin integer;
imax integer;
BEGIN
-- TABLE ROWS REFERENCES
imin := min(hig_dra_pk) FROM pgh_hgm.pghft_hydro_intel;
imax := max(hig_dra_pk) FROM pgh_hgm.pghft_hydro_intel;
RAISE NOTICE 'LOOP SETUP DRA_PK = % - %',imin,imax;
-- DROP AND CREATE INDEXES
-- args: (only_drop, index_drn_dra, index_dra_wtc, index_upa, index_elpdrn, index_elpupn)
PERFORM pgh_hgm.pghfn_utils_index_dropcreate(FALSE, TRUE, TRUE, FALSE, FALSE, FALSE);
--------------------------------------------------------
-- MAIN LOOP - ASSUMES EXISTING DRA_PK FROM IMIN TO IMAX
--------------------------------------------------------
FOR i IN imin..imax LOOP
RAISE NOTICE 'BEGIN OF PROCESS %/%: %', i,imax,timeofday();
------------------------------------------------------
-- CALCULATE/UPDATE ATTRIBUTE
------------------------------------------------------
-- EXPERIMENTAL: "RING APPROACH" VARIANTS OF SOME CATCHMENTS ATTRIBUTES
UPDATE pgh_hgm.pghft_hydro_intel
SET
hig_dra_axislength_ring = a.axislength_ring,
hig_dra_shapefactor_ring = a.shapefactor_ring,
hig_dra_formfactor_ring = a.formfactor_ring,
hig_dra_reliefratio_ring = a.reliefratio_ring
FROM (
SELECT
*
FROM
pgh_hgm.pghfn_dra_axislength_ring(i,srid_length), -- axial length
pgh_hgm.pghfn_dra_shapefactor_ring(i,srid_area,srid_length), -- shape factor
pgh_hgm.pghfn_dra_formfactor_ring(i,srid_area,srid_length), -- form factor
pgh_hgm.pghfn_dra_reliefratio_ring(i,srid_length) -- relief ratio (require catchment DEM)
) a
WHERE hig_dra_pk = i AND hig_wtc_pk IS NOT NULL;
-- FINISH
END LOOP;
time_ := timeofday();
RAISE NOTICE 'END OF PROCESS IN : %', time_;
RETURN 'OK';
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION pgh_hgm.pghfn_calculate_dra_bonus_river(
srid_area integer,
srid_length integer)
RETURNS character varying AS
$BODY$
/*
CALCULATE LOCAL CATCHMENT - AXIS LENGTH, SHAPEFACTOR, FORMFACTOR, RELIEF RATIO
(AXIS LENGTH ~ RIVER LENGTH APPROACH)
*/
DECLARE
time_ timestamp;
i integer;
imin integer;
imax integer;
BEGIN
-- TABLE ROWS REFERENCES
imin := min(hig_dra_pk) FROM pgh_hgm.pghft_hydro_intel;
imax := max(hig_dra_pk) FROM pgh_hgm.pghft_hydro_intel;
RAISE NOTICE 'LOOP SETUP DRA_PK = % - %',imin,imax;
-- DROP AND CREATE INDEXES
-- args: (only_drop, index_drn_dra, index_dra_wtc, index_upa, index_elpdrn, index_elpupn)
PERFORM pgh_hgm.pghfn_utils_index_dropcreate(FALSE, TRUE, TRUE, FALSE, FALSE, FALSE);
--------------------------------------------------------
-- MAIN LOOP - ASSUMES EXISTING DRA_PK FROM IMIN TO IMAX
--------------------------------------------------------
FOR i IN imin..imax LOOP
RAISE NOTICE 'BEGIN OF PROCESS %/%: %', i,imax,timeofday();
------------------------------------------------------
-- CALCULATE/UPDATE ATTRIBUTE
------------------------------------------------------
-- EXPERIMENTAL: "RIVER AXIS" VARIANTS OF SOME CATCHMENTS ATTRIBUTES
UPDATE pgh_hgm.pghft_hydro_intel
SET
hig_dra_axislength_river = a.axislength_river,
hig_dra_shapefactor_river = a.shapefactor_river,
hig_dra_formfactor_river = a.formfactor_river,
hig_dra_reliefratio_river = a.reliefratio_river
FROM (
SELECT
*
FROM
pgh_hgm.pghfn_dra_axislength_river(i,srid_length), -- axial length
pgh_hgm.pghfn_dra_shapefactor_river(i,srid_area,srid_length), -- shape factor
pgh_hgm.pghfn_dra_formfactor_river(i,srid_area,srid_length), -- form factor
pgh_hgm.pghfn_dra_reliefratio_river(i,srid_length) -- relief ratio (require catchment DEM)
) a
WHERE hig_dra_pk = i AND hig_wtc_pk IS NOT NULL;
-- FINISH
END LOOP;
time_ := timeofday();
RAISE NOTICE 'END OF PROCESS IN : %', time_;
RETURN 'OK';
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION pgh_hgm.pghfn_calculate_dra_bonus_schumm(
srid_area integer,
srid_length integer)
RETURNS character varying AS
$BODY$
/*
CALCULATE LOCAL CATCHMENT - AXIS LENGTH, SHAPEFACTOR, FORMFACTOR, RELIEF RATIO
(SCHUMM'S EQUATIONS APPROACH)
*/
DECLARE
time_ timestamp;
i integer;
imin integer;
imax integer;
BEGIN
-- TABLE ROWS REFERENCES
imin := min(hig_dra_pk) FROM pgh_hgm.pghft_hydro_intel;
imax := max(hig_dra_pk) FROM pgh_hgm.pghft_hydro_intel;
RAISE NOTICE 'LOOP SETUP DRA_PK = % - %',imin,imax;
-- DROP AND CREATE INDEXES
-- args: (only_drop, index_drn_dra, index_dra_wtc, index_upa, index_elpdrn, index_elpupn)
PERFORM pgh_hgm.pghfn_utils_index_dropcreate(FALSE, TRUE, TRUE, FALSE, FALSE, FALSE);
--------------------------------------------------------
-- MAIN LOOP - ASSUMES EXISTING DRA_PK FROM IMIN TO IMAX
--------------------------------------------------------
FOR i IN imin..imax LOOP