-
Notifications
You must be signed in to change notification settings - Fork 0
/
dz_sdotxt_deploy.sql
3281 lines (2577 loc) · 96.6 KB
/
dz_sdotxt_deploy.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
WHENEVER SQLERROR EXIT -99;
WHENEVER OSERROR EXIT -98;
SET DEFINE OFF;
--******************************--
PROMPT Types/DZ_SDOTXT_LABELED.tps
CREATE OR REPLACE TYPE dz_sdotxt_labeled FORCE
AUTHID CURRENT_USER
AS OBJECT (
shape_label VARCHAR2(4000 Char)
,shape MDSYS.SDO_GEOMETRY
,CONSTRUCTOR FUNCTION dz_sdotxt_labeled
RETURN SELF AS RESULT
);
/
GRANT EXECUTE ON dz_sdotxt_labeled TO public;
--******************************--
PROMPT Types/DZ_SDOTXT_LABELED.tpb
CREATE OR REPLACE TYPE BODY dz_sdotxt_labeled
AS
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
CONSTRUCTOR FUNCTION dz_sdotxt_labeled
RETURN SELF AS RESULT
AS
BEGIN
RETURN;
END dz_sdotxt_labeled;
END;
/
--******************************--
PROMPT Collections/DZ_SDOTXT_LABELED_LIST.tps
CREATE OR REPLACE TYPE dz_sdotxt_labeled_list FORCE
AS
TABLE OF dz_sdotxt_labeled;
/
GRANT EXECUTE ON dz_sdotxt_labeled_list TO public;
--******************************--
PROMPT Packages/DZ_SDOTXT_UTIL.pks
CREATE OR REPLACE PACKAGE dz_sdotxt_util
AUTHID CURRENT_USER
AS
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION downsize_2d(
p_input IN MDSYS.SDO_GEOMETRY
) RETURN MDSYS.SDO_GEOMETRY;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION downsize_2dM(
p_input IN MDSYS.SDO_GEOMETRY
) RETURN MDSYS.SDO_GEOMETRY;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION downsize_3d(
p_input IN MDSYS.SDO_GEOMETRY
) RETURN MDSYS.SDO_GEOMETRY;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION indent(
p_level IN NUMBER
,p_amount IN VARCHAR2 DEFAULT ' '
) RETURN VARCHAR2;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION pretty(
p_input IN CLOB
,p_level IN NUMBER
,p_amount IN VARCHAR2 DEFAULT ' '
,p_linefeed IN VARCHAR2 DEFAULT CHR(10)
) RETURN CLOB;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION blob2clob(
p_input IN BLOB
,p_decompress IN VARCHAR2 DEFAULT 'FALSE'
) RETURN CLOB;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION clob2blob(
p_input IN CLOB
,p_compress IN VARCHAR2 DEFAULT 'FALSE'
,p_comp_qual IN NUMBER DEFAULT 6
) RETURN BLOB;
END dz_sdotxt_util;
/
GRANT EXECUTE ON dz_sdotxt_util TO PUBLIC;
--******************************--
PROMPT Packages/DZ_SDOTXT_UTIL.pkb
CREATE OR REPLACE PACKAGE BODY dz_sdotxt_util
AS
----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION true_point(
p_input IN MDSYS.SDO_GEOMETRY
) RETURN MDSYS.SDO_GEOMETRY
AS
BEGIN
IF p_input.SDO_POINT IS NOT NULL
THEN
RETURN p_input;
END IF;
IF p_input.get_gtype() = 1
THEN
IF p_input.get_dims() = 2
THEN
RETURN MDSYS.SDO_GEOMETRY(
p_input.SDO_GTYPE
,p_input.SDO_SRID
,MDSYS.SDO_POINT_TYPE(
p_input.SDO_ORDINATES(1)
,p_input.SDO_ORDINATES(2)
,NULL
)
,NULL
,NULL
);
ELSIF p_input.get_dims() = 3
THEN
RETURN MDSYS.SDO_GEOMETRY(
p_input.SDO_GTYPE
,p_input.SDO_SRID
,MDSYS.SDO_POINT_TYPE(
p_input.SDO_ORDINATES(1)
,p_input.SDO_ORDINATES(2)
,p_input.SDO_ORDINATES(3)
)
,NULL
,NULL
);
ELSE
RAISE_APPLICATION_ERROR(
-20001
,'function true_point can only work on 2 and 3 dimensional points - dims=' || p_input.get_dims() || ' '
);
END IF;
ELSE
RAISE_APPLICATION_ERROR(
-20001
,'function true_point can only work on point geometries'
);
END IF;
END true_point;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION downsize_2d(
p_input IN MDSYS.SDO_GEOMETRY
) RETURN MDSYS.SDO_GEOMETRY
AS
geom_2d MDSYS.SDO_GEOMETRY;
dim_count PLS_INTEGER;
gtype PLS_INTEGER;
n_points PLS_INTEGER;
n_ordinates PLS_INTEGER;
i PLS_INTEGER;
j PLS_INTEGER;
k PLS_INTEGER;
offset PLS_INTEGER;
BEGIN
IF p_input IS NULL
THEN
RETURN NULL;
END IF;
IF LENGTH (p_input.SDO_GTYPE) = 4
THEN
dim_count := p_input.get_dims();
gtype := p_input.get_gtype();
ELSE
RAISE_APPLICATION_ERROR(
-20001
,'unable to determine dimensionality from gtype'
);
END IF;
IF dim_count = 2
THEN
RETURN p_input;
END IF;
geom_2d := MDSYS.SDO_GEOMETRY(
2000 + gtype
,p_input.sdo_srid
,p_input.sdo_point
,MDSYS.SDO_ELEM_INFO_ARRAY()
,MDSYS.SDO_ORDINATE_ARRAY()
);
IF geom_2d.sdo_point IS NOT NULL
THEN
geom_2d.sdo_point.z := NULL;
geom_2d.sdo_elem_info := NULL;
geom_2d.sdo_ordinates := NULL;
ELSE
n_points := p_input.SDO_ORDINATES.COUNT / dim_count;
n_ordinates := n_points * 2;
geom_2d.SDO_ORDINATES.EXTEND(n_ordinates);
j := p_input.SDO_ORDINATES.FIRST;
k := 1;
FOR i IN 1 .. n_points
LOOP
geom_2d.SDO_ORDINATES(k) := p_input.SDO_ORDINATES(j);
geom_2d.SDO_ORDINATES(k + 1) := p_input.SDO_ORDINATES(j + 1);
j := j + dim_count;
k := k + 2;
END LOOP;
geom_2d.sdo_elem_info := p_input.sdo_elem_info;
i := geom_2d.SDO_ELEM_INFO.FIRST;
WHILE i < geom_2d.SDO_ELEM_INFO.LAST
LOOP
offset := geom_2d.SDO_ELEM_INFO(i);
geom_2d.SDO_ELEM_INFO(i) := (offset - 1) / dim_count * 2 + 1;
i := i + 3;
END LOOP;
END IF;
IF geom_2d.SDO_GTYPE = 2001
THEN
RETURN true_point(geom_2d);
ELSE
RETURN geom_2d;
END IF;
END downsize_2d;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION downsize_2dM(
p_input IN MDSYS.SDO_GEOMETRY
) RETURN MDSYS.SDO_GEOMETRY
AS
geom_2dm MDSYS.SDO_GEOMETRY;
dim_count PLS_INTEGER;
measure_chk PLS_INTEGER;
gtype PLS_INTEGER;
n_points PLS_INTEGER;
n_ordinates PLS_INTEGER;
i PLS_INTEGER;
j PLS_INTEGER;
k PLS_INTEGER;
offset PLS_INTEGER;
BEGIN
IF p_input IS NULL
THEN
RETURN NULL;
END IF;
IF LENGTH (p_input.SDO_GTYPE) = 4
THEN
dim_count := p_input.get_dims();
measure_chk := p_input.get_lrs_dim();
gtype := p_input.get_gtype();
ELSE
RAISE_APPLICATION_ERROR(
-20001
,'unable to determine dimensionality from gtype'
);
END IF;
--------------------------------------------------------------------------
-- Simple 2D input so just throw it back
--------------------------------------------------------------------------
IF dim_count = 2
THEN
RETURN p_input;
--------------------------------------------------------------------------
-- 2D + measure on 3 so just throw it back
--------------------------------------------------------------------------
ELSIF dim_count = 3
AND measure_chk = 3
THEN
RETURN p_input;
--------------------------------------------------------------------------
-- Simple 3D so downsize to 2D
--------------------------------------------------------------------------
ELSIF dim_count = 3
AND measure_chk = 0
THEN
RETURN downsize_2d(p_input);
--------------------------------------------------------------------------
-- 4D so assume measure on the 4
--------------------------------------------------------------------------
ELSIF dim_count = 4
THEN
--THIS IS BECAUSE ArcSDE is DUMB!
measure_chk := 4;
END IF;
IF gtype = 1
THEN
geom_2dm := MDSYS.SDO_GEOMETRY(
3300 + gtype
,p_input.sdo_srid
,MDSYS.SDO_POINT_TYPE(NULL,NULL,NULL)
,NULL
,NULL
);
geom_2dm.SDO_POINT.X := p_input.SDO_ORDINATES(1);
geom_2dm.SDO_POINT.Y := p_input.SDO_ORDINATES(2);
geom_2dm.SDO_POINT.Z := p_input.SDO_ORDINATES(4);
RETURN geom_2dm;
ELSE
geom_2dm := MDSYS.SDO_GEOMETRY(
3300 + gtype
,p_input.sdo_srid
,NULL
,MDSYS.SDO_ELEM_INFO_ARRAY()
,MDSYS.SDO_ORDINATE_ARRAY()
);
END IF;
n_points := p_input.SDO_ORDINATES.COUNT / dim_count;
n_ordinates := n_points * 3;
geom_2dm.SDO_ORDINATES.EXTEND(n_ordinates);
j := p_input.SDO_ORDINATES.FIRST;
k := 1;
FOR i IN 1 .. n_points
LOOP
geom_2dm.SDO_ORDINATES(k) := p_input.SDO_ORDINATES(j);
geom_2dm.SDO_ORDINATES(k + 1) := p_input.SDO_ORDINATES(j + 1);
geom_2dm.SDO_ORDINATES(k + 2) := p_input.SDO_ORDINATES(j + 3);
j := j + dim_count;
k := k + 3;
END LOOP;
geom_2dm.sdo_elem_info := p_input.sdo_elem_info;
i := geom_2dm.SDO_ELEM_INFO.FIRST;
WHILE i < geom_2dm.SDO_ELEM_INFO.LAST
LOOP
offset := geom_2dm.SDO_ELEM_INFO(i);
geom_2dm.SDO_ELEM_INFO(i) := (offset - 1) / dim_count * 2 + 1;
i := i + 3;
END LOOP;
RETURN geom_2dm;
END downsize_2dM;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION downsize_3d(
p_input IN MDSYS.SDO_GEOMETRY
) RETURN MDSYS.SDO_GEOMETRY
AS
geom_3d MDSYS.SDO_GEOMETRY;
num_lrs NUMBER;
dim_count PLS_INTEGER;
gtype PLS_INTEGER;
n_points PLS_INTEGER;
n_ordinates PLS_INTEGER;
i PLS_INTEGER;
j PLS_INTEGER;
k PLS_INTEGER;
offset PLS_INTEGER;
BEGIN
IF p_input IS NULL
THEN
RETURN NULL;
END IF;
IF LENGTH(p_input.SDO_GTYPE) = 4
THEN
dim_count := p_input.get_dims();
gtype := p_input.get_gtype();
num_lrs := p_input.get_lrs_dim();
ELSE
RAISE_APPLICATION_ERROR(
-20001
,'unable to determine dimensionality from gtype'
);
END IF;
IF dim_count = 3 AND num_lrs = 0
THEN
RETURN p_input;
ELSIF dim_count = 3 AND num_lrs != 0
THEN
RETURN downsize_2d(p_input);
ELSIF dim_count = 4 AND num_lrs = 0
THEN
-- we ASSUME that we remove the 4th dimension
num_lrs := 4;
END IF;
geom_3d := MDSYS.SDO_GEOMETRY(
3000 + gtype
,p_input.SDO_SRID
,p_input.SDO_POINT
,MDSYS.SDO_ELEM_INFO_ARRAY()
,MDSYS.SDO_ORDINATE_ARRAY()
);
IF geom_3d.sdo_point IS NOT NULL
THEN
geom_3d.sdo_elem_info := NULL;
geom_3d.sdo_ordinates := NULL;
ELSE
n_points := p_input.SDO_ORDINATES.COUNT / dim_count;
n_ordinates := n_points * 3;
geom_3d.SDO_ORDINATES.EXTEND(n_ordinates);
j := p_input.SDO_ORDINATES.FIRST;
k := 1;
FOR i IN 1 .. n_points
LOOP
geom_3d.SDO_ORDINATES(k) := p_input.SDO_ORDINATES(j);
geom_3d.SDO_ORDINATES(k + 1) := p_input.SDO_ORDINATES(j + 1);
IF num_lrs = 4
THEN
geom_3d.SDO_ORDINATES(k + 2) := p_input.SDO_ORDINATES(j + 2);
ELSIF num_lrs = 3
THEN
geom_3d.SDO_ORDINATES(k + 2) := p_input.SDO_ORDINATES(j + 3);
END IF;
j := j + dim_count;
k := k + 3;
END LOOP;
geom_3d.sdo_elem_info := p_input.sdo_elem_info;
i := geom_3d.SDO_ELEM_INFO.FIRST;
WHILE i < geom_3d.SDO_ELEM_INFO.LAST
LOOP
offset := geom_3d.SDO_ELEM_INFO(i);
geom_3d.SDO_ELEM_INFO(i) := (offset - 1) / dim_count * 3 + 1;
i := i + 4;
END LOOP;
END IF;
IF geom_3d.SDO_GTYPE = 2001
THEN
RETURN true_point(geom_3d);
ELSE
RETURN geom_3d;
END IF;
END downsize_3d;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION indent(
p_level IN NUMBER
,p_amount IN VARCHAR2 DEFAULT ' '
) RETURN VARCHAR2
AS
str_output VARCHAR2(4000 Char) := '';
BEGIN
IF p_level IS NOT NULL
AND p_level > 0
THEN
FOR i IN 1 .. p_level
LOOP
str_output := str_output || p_amount;
END LOOP;
RETURN str_output;
ELSE
RETURN '';
END IF;
END indent;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION pretty(
p_input IN CLOB
,p_level IN NUMBER
,p_amount IN VARCHAR2 DEFAULT ' '
,p_linefeed IN VARCHAR2 DEFAULT CHR(10)
) RETURN CLOB
AS
str_amount VARCHAR2(4000 Char) := p_amount;
str_linefeed VARCHAR2(2 Char) := p_linefeed;
BEGIN
--------------------------------------------------------------------------
-- Step 10
-- Process Incoming Parameters
--------------------------------------------------------------------------
IF p_amount IS NULL
THEN
str_amount := ' ';
END IF;
--------------------------------------------------------------------------
-- Step 20
-- If input is NULL, then do nothing
--------------------------------------------------------------------------
IF p_input IS NULL
THEN
RETURN NULL;
END IF;
--------------------------------------------------------------------------
-- Step 30
-- Return indented and line fed results
--------------------------------------------------------------------------
IF p_level IS NULL
THEN
RETURN p_input;
ELSIF p_level = -1
THEN
RETURN p_input || TO_CLOB(str_linefeed);
ELSE
RETURN TO_CLOB(indent(p_level,str_amount)) || p_input || TO_CLOB(str_linefeed);
END IF;
END pretty;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION blob2clob(
p_input IN BLOB
,p_decompress IN VARCHAR2 DEFAULT 'FALSE'
) RETURN CLOB
AS
l_blob BLOB := p_input;
l_clob CLOB;
l_src_offset NUMBER;
l_dest_offset NUMBER;
v_lang_context NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
l_warning NUMBER;
l_amount NUMBER;
BEGIN
--------------------------------------------------------------------------
-- Step 10
-- Check over incoming parameters
--------------------------------------------------------------------------
IF p_input IS NULL
OR DBMS_LOB.GETLENGTH(p_input) = 0
THEN
RETURN NULL;
END IF;
--------------------------------------------------------------------------
-- Step 20
-- Decompress input blob if requested
--------------------------------------------------------------------------
IF p_decompress = 'TRUE'
THEN
l_blob := UTL_COMPRESS.LZ_UNCOMPRESS(l_blob);
END IF;
--------------------------------------------------------------------------
-- Step 30
-- Generate a temporary clob to hold results
--------------------------------------------------------------------------
DBMS_LOB.CREATETEMPORARY(l_clob, TRUE);
l_src_offset := 1;
l_dest_offset := 1;
l_amount := DBMS_LOB.GETLENGTH(l_blob);
--------------------------------------------------------------------------
-- Step 40
-- Convert blob to clob
--------------------------------------------------------------------------
DBMS_LOB.CONVERTTOCLOB(
l_clob
,l_blob
,l_amount
,l_src_offset
,l_dest_offset
,1
,v_lang_context
,l_warning
);
--------------------------------------------------------------------------
-- Step 50
-- Return results
--------------------------------------------------------------------------
RETURN l_clob;
END blob2clob;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
FUNCTION clob2blob(
p_input IN CLOB
,p_compress IN VARCHAR2 DEFAULT 'FALSE'
,p_comp_qual IN NUMBER DEFAULT 6
) RETURN BLOB
AS
l_blob BLOB;
l_src_offset NUMBER;
l_dest_offset NUMBER;
v_lang_context NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
l_warning NUMBER;
l_amount NUMBER;
BEGIN
--------------------------------------------------------------------------
-- Step 10
-- Check over incoming parameters
--------------------------------------------------------------------------
IF p_input IS NULL
OR DBMS_LOB.GETLENGTH(p_input) = 0
THEN
RETURN NULL;
END IF;
--------------------------------------------------------------------------
-- Step 20
-- Generate a temporary blob to hold results
--------------------------------------------------------------------------
DBMS_LOB.CREATETEMPORARY(l_blob, TRUE);
l_src_offset := 1;
l_dest_offset := 1;
l_amount := DBMS_LOB.GETLENGTH(p_input);
--------------------------------------------------------------------------
-- Step 30
-- Convert clob to blob
--------------------------------------------------------------------------
DBMS_LOB.CONVERTTOBLOB(
l_blob
,p_input
,l_amount
,l_src_offset
,l_dest_offset
,1
,v_lang_context
,l_warning
);
--------------------------------------------------------------------------
-- Step 40
-- Compress blob if requested
--------------------------------------------------------------------------
IF p_compress = 'TRUE'
THEN
RETURN UTL_COMPRESS.LZ_COMPRESS(
src => l_blob
,quality => p_comp_qual
);
END IF;
--------------------------------------------------------------------------
-- Step 50
-- Return results
--------------------------------------------------------------------------
RETURN l_blob;
END clob2blob;
END dz_sdotxt_util;
/
--******************************--
PROMPT Packages/DZ_SDOTXT_MAIN.pks
CREATE OR REPLACE PACKAGE dz_sdotxt_main
AUTHID CURRENT_USER
AS
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
/*
header: DZ_SDOTXT
- Release: 2.0
- Commit Date: Sat Apr 4 11:41:39 2020 -0400
Utilities for the conversion and inspection of Oracle Spatial objects as
text.
Generally there are few reasons for you to want to manifest Oracle Spatial
objects as SQL text. So you should only be using this code if you need to
generate an example for an OTN posting or Oracle SR, or if you are exchanging
a very modest amount of data with a colleague who has limited access to
Oracle. Overwhelmingly the proper way to exchange Oracle data is via datapump.
See the DZ_TESTDATA project as an example of what this module can do.
*/
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
/*
Function: dz_sdotxt_main.sdo2sql
Utility to convert an Oracle Spatial object into text format.
Parameters:
p_input - object to convert to text format
p_2d_flag - optional TRUE/FALSE flag to remove any third or fourth
dimensions on geometries before text conversion.
p_output_srid - optional srid to transform geometries to before text
conversion.
p_pretty_print - optional pretty print indent value
Returns:
CLOB text value representing an Oracle Spatial object.
Notes:
- Input objects may include MDSYS.SDO_GEOMETRY, MDSYS.SDO_GEOMETRY_ARRAY,
MDSYS.SDO_POINT_TYPE, MDSYS.SDO_ELEM_INFO_ARRAY, MDSYS.SDO_ORDINATE_ARRAY,
MDSYS.SDO_GEORASTER, MDSYS.SDO_RASTER and MDSYS.SDO_DIM_ARRAY.
- Note that Oracle is not PostgreSQL or other database systems where large
objects can be comfortably dumped to text. Attempting to dump a 300,000
vertice geometry is going to fail, attempting to dump a 70 gig raster rdt
table is going to fail, attempting to feed more than a few meg
of generated text data back through sqlplus is also going to fail. These
utilities are provided for very modest purposes primarily to inspect the
details of small example spatial objects or package up one or two smaller
sized objects for transport via text to a collaborator. In all situations
the use of Oracle datapump to import and export spatial data is the way to
go.
*/
FUNCTION sdo2sql(
p_input IN MDSYS.SDO_GEOMETRY
,p_2d_flag IN VARCHAR2 DEFAULT 'FALSE'
,p_output_srid IN NUMBER DEFAULT NULL
,p_pretty_print IN NUMBER DEFAULT 0
) RETURN CLOB;
FUNCTION sdo2sql(
p_input IN MDSYS.SDO_GEOMETRY_ARRAY
,p_2d_flag IN VARCHAR2 DEFAULT 'FALSE'
,p_output_srid IN NUMBER DEFAULT NULL
,p_pretty_print IN NUMBER DEFAULT 0
) RETURN CLOB;
FUNCTION sdo2sql(
p_input IN MDSYS.SDO_POINT_TYPE
,p_pretty_print IN NUMBER DEFAULT 0
) RETURN CLOB;
FUNCTION sdo2sql(
p_input IN MDSYS.SDO_ELEM_INFO_ARRAY
,p_pretty_print IN NUMBER DEFAULT 0
) RETURN CLOB;
FUNCTION sdo2sql(
p_input IN MDSYS.SDO_ORDINATE_ARRAY
,p_pretty_print IN NUMBER DEFAULT 0
) RETURN CLOB;
FUNCTION sdo2sql(
p_input IN MDSYS.SDO_DIM_ARRAY
,p_pretty_print IN NUMBER DEFAULT 0
) RETURN CLOB;
-- Note if the package fails to compile in Oracle 12c due to the Georaster
-- object below, then either comment out this function in both spec and body
-- or activate the Georaster object as detailed at
-- https://docs.oracle.com/database/121/SPATL/ensuring-that-georaster-works-properly-installation-or-upgrade.htm#SPATL1560
FUNCTION sdo2sql(
p_input IN MDSYS.SDO_GEORASTER
,p_pretty_print IN NUMBER DEFAULT 0
) RETURN CLOB;
FUNCTION sdo2sql(
p_input IN MDSYS.SDO_RASTER
,p_pretty_print IN NUMBER DEFAULT 0
) RETURN CLOB;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
/*
Function: dz_sdotxt_main.sdo2sql_nvl
Utility to convert an Oracle Spatial object into text format with an NVL
option to return a given output when input is NULL.
Parameters:
p_input - MDSYS.SDO_GEOMETRY to convert to text format.
p_is_null - value to return if input object is NULL.
p_2d_flag - optional TRUE/FALSE flag to remove any third or fourth
dimensions on geometry before text conversion.
p_output_srid - optional srid to transform geometry to before text
conversion.
p_pretty_print - optional pretty print indent value
Returns:
CLOB text value representing an Oracle Spatial object.
*/
FUNCTION sdo2sql_nvl(
p_input IN MDSYS.SDO_GEOMETRY
,p_is_null IN CLOB
,p_2d_flag IN VARCHAR2 DEFAULT 'FALSE'
,p_output_srid IN NUMBER DEFAULT NULL
,p_pretty_print IN NUMBER DEFAULT 0
) RETURN CLOB;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
/*
Function: dz_sdotxt_main.blob2sql
Utility to convert a blob into textual hex usable as a right side assignment
in SQL or PLSQL. In order to use the results in SQL this is greatly limited
to 4000 characters and in PLSQL to 32676 characters which when dumping a
BLOB is pretty limiting. Use blob2plsql for a more scaleable work-around.
Parameters:
p_input - BLOB to convert to sql text.
Returns:
CLOB result.
*/
FUNCTION blob2sql(
p_input IN BLOB
) RETURN CLOB;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
/*
Function: dz_sdotxt_main.blob2plsql
Utility to convert a blob into textual hex usable as a series of DBMS_LOB
statements which can be then be combined and used as a bind variable in
PLSQL dynamic SQL statememts.
Parameters:
p_input - BLOB to convert to sql text.
p_lob_name - the lob variable name in the statements, default is dz_lob.
Use different names if you are dumping multiple blobs.
p_delim_value - the delimiter to place at the end of each statement, the
default is a line feed to make sqlplus happy. Set to NULL if you want no
linefeeds.
Returns:
CLOB result.
*/
FUNCTION blob2plsql(
p_input IN BLOB
,p_lob_name IN VARCHAR2 DEFAULT 'dz_lob'
,p_delim_value IN VARCHAR2 DEFAULT CHR(10)
) RETURN CLOB;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
/*
Function: dz_sdotxt_main.sdo2geomblob
Utility to convert a geometry into the secret bar-delimited CLOB format
which is then compressed with UTL_COMPRESS into a BLOB.
This utility has a very specific use case of squeezing down a larger geometry
into a blob which can be expressed as sql text using blob2plsql and thus
shared in a OTN forum or other situation whereby a collaborator may have
limited access to Oracle datapump. I can think of no scenarios where this
would be appropriate for production or other true ETL tasks. The proper way
to share Oracle data is via datapump.
The easiest way to convert the blob created by this procedure back into
MDSYS.SDO_GEOMETRY is via geomblob2sdo. Neither of these functions are that
overly complex. Note that in many cases it may be easier to just convert
your geometry to a WKB BLOB via MDSYS.SDO_UTIL.TO_WKBGEOMETRY and then
dump to text via blob2plsql. To rebuild that blob into a geometry just push
the blob into the MDSYS.SDO_GEOMETRY constructor. However, the Java-based
WKB handling in Oracle Spatial is very old and only supports the most
basic geometry types corresponding to the OGC Simple Features version 1.0.
Its not going to work for LRS, 3D, or compound geometries. This utility uses
the secret SDO_UTIL.TO_CLOB function to generate a bar-delimited version of
the geometry object which while larger in size, should support all forms of
Oracle Spatial geometries.
Parameters:
p_input - MDSYS.SDO_GEOMETRY
p_comp_qual - UTL_COMPRESS.LZ_COMPRESS compression quality, the default of
nine is the highest compression as why would you be doing this if you were
not trying to pack things down as much as possible. Change if you like.
Returns:
BLOB result.
*/
FUNCTION sdo2geomblob(
p_input IN MDSYS.SDO_GEOMETRY
,p_comp_qual IN NUMBER DEFAULT 9
) RETURN BLOB;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
/*
Function: dz_sdotxt_main.geomblob2sdo
Utility to convert a blob of compressed bar-delimited geometry back into