SDO_UTIL.REMOVE_DUPLICATE_VERTICES

Hello!
I'm doing:
SELECT SDO_UTIL.REMOVE_DUPLICATE_VERTICES(
SDO_GEOMETRY(2003, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1),
SDO_ORDINATE_ARRAY(15.7880529, 39.969326, 15.7555701, 39.9241403, 15.6437856, 40.043365, 15.6764499, 40.0558863, 15.6766314, 40.0578825, 15.721454, 40.3257296, 15.7210911, 40.3277258, 15.5336344, 40.572708, 15.5325456, 40.5736153, 15.4654023, 40.6336813, 15.4654023, 40.6336813, 15.3363784, 40.8347482, 15.5434337, 41.0581356, 16.2010747, 40.9185865, 16.2032523, 40.9171348, 16.2273876, 40.8792079, 16.2266617, 40.8775747, 16.6632744, 40.7487322, 16.6634559, 40.7487322, 16.8683336, 40.3984984, 16.6447646, 40.1206705, 15.7880529, 39.969326, 15.7880529, 39.969326)),
0.0000005
) FROM regionc;
but it doesn't do ANYTHING the 2 duplicate coordenates are still there :(
I can see them every time :(
Does anyone has any idea why it doesn't work?
Thank you very much in advance!
I really don't want to do it manually :(

Hello!!!
Thank you for your answer.
I think that my machine is doing something wird but I have no idea how to fix it.
Look what I did and what I get:
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> create table testrd (geo mdsys.sdo_geometry);
Table créée.
SQL> insert into testrd SELECT
2 SDO_UTIL.REMOVE_DUPLICATE_VERTICES(
3 SDO_GEOMETRY(2003, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1),
4 SDO_ORDINATE_ARRAY(15.7880529, 39.969326, 15.7555701, 39.9241403, 15.6437856, 40.043365, 15.676
4499, 40.0558863,
5 15.6766314, 40.0578825, 15.721454, 40.3257296, 15.7210911, 40.3277258, 15.5336344, 40.572708, 1
5.5325456,
6 40.5736153, 15.4654023, 40.6336813, 15.4654023, 40.6336813, 15.3363784, 40.8347482, 15.5434337,
41.0581356,
7 16.2010747, 40.9185865, 16.2032523, 40.9171348, 16.2273876, 40.8792079, 16.2266617, 40.8775747,
16.6632744,
8 40.7487322, 16.6634559, 40.7487322, 16.8683336, 40.3984984, 16.6447646, 40.1206705, 15.7880529,
39.969326,
9 15.7880529, 39.969326)),
10 0.0000005
11 ) FROM regionc;
24 ligne(s) créée(s).
SQL> commit;
Validation effectuée.
SQL> select t.id,t.x,t.y
2 from testrd g, table(sdo_util.getvertices(g.geo)) t;
ID X Y
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
ID X Y
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
ID X Y
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
ID X Y
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
ID X Y
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
ID X Y
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
ID X Y
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
ID X Y
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
ID X Y
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
ID X Y
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
ID X Y
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
ID X Y
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
ID X Y
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
ID X Y
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
ID X Y
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
ID X Y
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
ID X Y
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
ID X Y
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
ID X Y
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
ID X Y
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
ID X Y
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
ID X Y
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
ID X Y
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
ID X Y
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
ID X Y
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
ID X Y
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
ID X Y
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
ID X Y
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
ID X Y
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
ID X Y
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
ID X Y
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
ID X Y
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
ID X Y
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
ID X Y
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
ID X Y
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
ID X Y
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
ID X Y
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
ID X Y
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
ID X Y
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
ID X Y
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
ID X Y
21 15,7880529 39,969326
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
ID X Y
11 15,3363784 40,8347482
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
ID X Y
1 15,7880529 39,969326
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
ID X Y
12 15,5434337 41,0581356
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
1 15,7880529 39,969326
ID X Y
2 15,7555701 39,9241403
3 15,6437856 40,043365
4 15,6764499 40,0558863
5 15,6766314 40,0578825
6 15,721454 40,3257296
7 15,7210911 40,3277258
8 15,5336344 40,572708
9 15,5325456 40,5736153
10 15,4654023 40,6336813
11 15,3363784 40,8347482
12 15,5434337 41,0581356
ID X Y
13 16,2010747 40,9185865
14 16,2032523 40,9171348
15 16,2273876 40,8792079
16 16,2266617 40,8775747
17 16,6632744 40,7487322
18 16,6634559 40,7487322
19 16,8683336 40,3984984
20 16,6447646 40,1206705
21 15,7880529 39,969326
504 ligne(s) sélectionnée(s).!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I don't know what it's doing! :(

Similar Messages

  • SDO_UTIL.REMOVE_DUPLICATE_VERTICES with curves

    Howdy,
    Database is 10.2.0.3 AIX64.
    I have an SDO_GEOMETRY that produces an ORA-13356// dups - doing a SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(g.GEOMETRY, 0.001)
    This is the bad boy:
    MDSYS.SDO_GEOMETRY(2002,2236,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,4,5,1,2,1,3,2,2,7,2,1,9,2,2,13,2,1),MDSYS.SDO_ORDINATE_ARRAY(894270.650844107,531988.579373758,894277.41318061,531991.900923698,894278.464283255,531993.83764281,894276.776710971,531995.254610514,894265.456019573,531994.675760649,894263.72801983,531993.854244224,894263.087039329,531992.051464053,894263.087039329,531992.051464053))
    I immediatly do a SDO_UTIL.REMOVE_DUPLICATE_VERTICES with the same tolerance.
    I get back this:
    MDSYS.SDO_GEOMETRY(2002,2236,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,4,5,1,2,1,3,2,2,7,2,1,9,2,2,11,2,1),MDSYS.SDO_ORDINATE_ARRAY(894270.650844107,531988.579373758,894277.41318061,531991.900923698,894278.464283255,531993.83764281,894276.776710971,531995.254610514,894265.456019573,531994.675760649,894263.72801983,531993.854244224,894263.087039329,531992.051464053)) ... the 13 and 14 elements have been removed from the above
    BUT ... this now throws a ORA-13354 //incorrect offset in ELEM_INFO_ARRAY --- yea it looks like it broke a curve transition
    Does SDO_UTIL.REMOVE_DUPLICATE_VERTICES do just that and NOT take into account the ETYPE and INTEPRETATION, potentially then producing an invalid geometry?
    Hope I asked it correctly ..
    r,
    dennis

    Dennis
    I can confirm the same result as you.
    it looks like te returned geometry from the sdo_util.REMOVE_DUPLICATE_VERTICES
    should look like:
    MDSYS.SDO_GEOMETRY(2002,2236,null,MDSYS.SDO_ELEM_INFO_ARRAY
    (1,4,*_4_*,
    1,2,1,
    3,2,2,
    7,2,1,
    9,2,2),
    MDSYS.SDO_ORDINATE_ARRAY
    (894270.650844107,531988.579373758,
    894277.41318061,531991.900923698,
    894278.464283255,531993.83764281,
    894276.776710971,531995.254610514,
    894265.456019573,531994.675760649,
    894263.72801983,531993.854244224,
    894263.087039329,531992.051464053))
    Where there are 4 triplets defining your geome in the Info_array and the last straigth line defintion should be removed.
    I guess, but that is up the oracle people to confirm, because the redundancy is located at the endpoint, is that the remove_duplicate_vertices function will keep the last vertex = endpoint as a fixed vertex, therefor removing the n-1 vertex in this case, and just update the last triplet in the info_array, without evaluating the previous element in the compound line string, in this case the last arc definition.
    Another reason can be that the implementation will remove the first of the two redundant vertices.
    This does not solve your problem but hopefully, with some comment from one of the oracle guys, at least could explain what is going on.
    Luc
    Edited by: lucvanlinden on Oct 10, 2008 9:24 AM

  • Sdo_util.remove_duplicate_vertices on an ORA-13341 line - session crash

    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for 64-bit Windows: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - ProductionLet's say I have an invalid geometry:
    sdo_geometry(2002, 8307, NULL, sdo_elem_info_array(1, 2, 1), sdo_ordinate_array(60, 60))with error: ORA-13341: a line geometry has fewer than two coordinates
    It is clearly an invalid geometry, but if I then try to run select sdo_util.remove_duplicate_vertices on it, I'd expect that either (a) I get NULL, (b) I get the original geometry or (c) I get a suitable error message. But instead the session crashes...
    SQL> select sdo_util.remove_duplicate_vertices(sdo_geometry(2002, 8307, NULL,
      2  sdo_elem_info_array(1, 2, 1), sdo_ordinate_array(60, 60)),0.00005)
      3  from dual
      4  /
    select sdo_util.remove_duplicate_vertices(sdo_geometry(2002, 8307, NULL,
    ERROR at line 1:
    ORA-03113: end-of-file on communication channel
    Process ID: 11156
    Session ID: 417 Serial number: 101Doesn't seem very nice.
    John

    I see that this is pretty much the same as:
    Bug 7329858: SDO_UTIL.REMOVE_DUPLICATE_VERTICES CAUSES ORA-07445 CORE DUMP

  • Convert multiline to simple line?

    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
    We are processing spatial data from another source to display in our GIS environment.
    The data is a set of multilines. The gtype is 2006. A typical geometry looks like:
    SDO_GTYPE     2006
    SDO_SRID      31370
    SDO_POINT.X   NULL     
    SDO_POINT.Y   NULL
    SDO_POINT.Z   NULL
    SDO_ELEM_INFO (1,2,1, 7,2,1)
    SDO_ORDINATES (105094.84, 195084.96,
                   105094.54, 195080.22,
                   105094.84, 195084.96,
                   105094.84, 195084.96,
                   105094.68, 195082.47 )Now, this is not an actual multiline... it's just encoded as a multiline, but if you look at the coordinates you'll see that the end point of the first line is the same as the beginning of the second line (105094.84, 195084.96).
    A better way to encode this geometry would be:
    SDO_GTYPE     2002 <---
    SDO_SRID      31370
    SDO_POINT.X   NULL     
    SDO_POINT.Y   NULL
    SDO_POINT.Z   NULL
    SDO_ELEM_INFO (1,2,1)
    SDO_ORDINATES (105094.84, 195084.96,
                   105094.54, 195080.22,
                   105094.84, 195084.96, <---
                   105094.68, 195082.47 )Is there a standard function in Oracle that does this conversion for me? Or do I have to write my own :)
    Thanks a lot!
    Rob

    Rob,
    Plenty of ways to skin this cat with the standard tools.
    with mLine as (
    select SDO_GEOMETRY(2006,31370,NULL,
    SDO_ELEM_INFO_Array (1,2,1, 7,2,1),
    SDO_ORDINATE_ARRAY (105094.84, 195084.96,
                   105094.54, 195080.22,
                   105094.84, 195084.96,
                   105094.84, 195084.96,
                   105094.68, 195082.47 )) as geom
    from dual
    select sdo_util.concat_lines(l1.geom,l2.geom) as line
      from (select sdo_util.extract(geom,1) as geom from mline) l1,
           (select sdo_util.extract(geom,2) as geom from mline) l2
    union all
    select sdo_geom.sdo_union(geom,geom,0.005) as line
      from mline l
    union all
    select sdo_util.remove_duplicate_vertices(sdo_geometry(2002,l.geom.sdo_srid,l.geom.sdo_point,SDO_ELEM_INFO_ARRAY(1,2,1),l.geom.sdo_ordinates),0.005) as line
      from mline l;
    -- Results
    LINE
    SDO_GEOMETRY(2002,31370,NULL,SDO_ELEM_INFO_ARRAY(1,2,1),SDO_ORDINATE_ARRAY(105094.84,195084.96, 105094.54,195080.22, 105094.84,195084.96, 105094.68,195082.47))
    SDO_GEOMETRY(2002,31370,NULL,SDO_ELEM_INFO_ARRAY(1,2,1),SDO_ORDINATE_ARRAY(105094.54,195080.22, 105094.68,195082.47, 105094.84,195084.96))
    SDO_GEOMETRY(2002,31370,NULL,SDO_ELEM_INFO_ARRAY(1,2,1),SDO_ORDINATE_ARRAY(105094.84,195084.96, 105094.54,195080.22, 105094.84,195084.96, 105094.68,195082.47))Note how SDO_UNION reorganizes and cleans up the linestring which you may not want.
    regards
    Simon

  • How to bridge (fill) gaps when converting a 2006 geometry  into a 2002 geometry

    Is it at all possible to bridge (fill) gaps when converting a 2006 geometry into a single 2002 geometry. I have a solution for the conversion from 2006 to 2002 provided by BHall but upon further investigation investigation of my dataset some of the multi line polygons have gaps which I need to fill and I am not sure how to go about this.
    Here is a simple example of what I am trying to achieve
    Before
    SELECT (sdo_geometry(2006, 81989, NULL,
                    mdsys.sdo_elem_info_array(1,2,1,5,2,1,9,2,1,13,2,1),
                    mdsys.sdo_ordinate_array(16,0.999,16.998,-0.001,17.253,-0.001,18.003,0.999,18.003,0.999,19.001,0.999,19.001,0.999,19.999,-0.001)))
      FROM dual
    After
    SELECT (sdo_geometry(2006, 81989,NULL,
                   mdsys.sdo_elem_info_array(1,2,1),
                   mdsys.sdo_ordinate_array(16,0.999,17.253,-0.001,18.003,0.999,19.001,0.999,19.999,-0.001))) FROM dual    
    Thanks in advance

    Okay Roché,
    You might need to break this problem down into smaller parts for the forum.  All your examples show the gap being replaced by a single vertice - e.g. you want to "snap" the gap together.  I'd suggest this is just complicating your question.  Once the gap is filled (with a line) then you can run SDO_UTIL.REMOVE_DUPLICATE_VERTICES afterwards to remove the new line if its below your tolerance.  I think that Bryan's code wrapped in remove duplicate vertices will solve your second scenario.  But overall I think it would be helpful to focus just on the filling and leave the snapping for a follow-up question.
    So back to scenario #1, below is some code I wrote a while back that might do what you want or at least get you started.     Note that the input must be a multistring and the multistring cannot be "spaghetti".  In other words each line in the multistring must be disjoint or at most touch other lines only at endpoints. The goal is to sift through the lines and create a single linestring using the smallest gaps.  It's not subtle and will indeed produce bad geometries if the inputs are setup in an impossible manner.  There are also some rare geodetic bugs with SDO_GEOM.RELATE that crop up.  So you'll note I test both distance and relate in some places.  That's intentional though kind of dumb.
    Hopefully this helps.  If you improve the code please shoot a copy back to me.
    Cheers,
    Paul   
    CREATE OR REPLACE PACKAGE dz_gap_fill
    AUTHID CURRENT_USER
    AS
       FUNCTION linear_gap_filler(
           p_input            IN  MDSYS.SDO_GEOMETRY
          ,p_tolerance        IN  NUMBER DEFAULT 0.05
       ) RETURN MDSYS.SDO_GEOMETRY;
    END dz_gap_fill;
    CREATE OR REPLACE PACKAGE BODY dz_gap_fill
    AS
       FUNCTION fast_point(
           p_x             IN  NUMBER
          ,p_y             IN  NUMBER
          ,p_z             IN  NUMBER DEFAULT NULL
          ,p_m             IN  NUMBER DEFAULT NULL
          ,p_srid          IN  NUMBER DEFAULT 8265
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
       BEGIN
          -- Step 10
          -- Check over incoming parameters
          IF p_x IS NULL
          OR p_y IS NULL
          THEN
             RAISE_APPLICATION_ERROR(-20001,'x and y cannot be NULL');
          END IF;
          -- Step 20
          -- Do the simplest solution first
          IF  p_z IS NULL
          AND p_m IS NULL
          THEN
             RETURN SDO_GEOMETRY(
                 2001
                ,p_srid
                ,SDO_POINT_TYPE(
                     p_x
                    ,p_y
                    ,NULL
                ,NULL
                ,NULL
          END IF;
          -- Step 30
          -- Do the other wilder choices
          IF p_z IS NULL
          AND p_m IS NOT NULL
          THEN
             RETURN SDO_GEOMETRY(
                 3301
                ,p_srid
                ,SDO_POINT_TYPE(
                     p_x
                    ,p_y
                    ,p_m
                ,NULL
                ,NULL
          ELSIF p_z IS NOT NULL
          AND   p_m IS NULL
          THEN
             RETURN SDO_GEOMETRY(
                 3001
                ,p_srid
                ,SDO_POINT_TYPE(
                     p_x
                    ,p_y
                    ,p_z
                ,NULL
                ,NULL
          ELSIF p_z IS NOT NULL
          AND   p_m IS NOT NULL
          THEN
             RETURN SDO_GEOMETRY(
                 4401
                ,p_srid
                ,NULL
                ,SDO_ELEM_INFO_ARRAY(1,1,1)
                ,SDO_ORDINATE_ARRAY(p_x,p_y,p_z,p_m)
          ELSE
             RAISE_APPLICATION_ERROR(-20001,'ERR!');
          END IF;
       END fast_point;
       FUNCTION get_start_point(
          p_input        IN  MDSYS.SDO_GEOMETRY
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
          int_dims PLS_INTEGER;
          int_gtyp PLS_INTEGER;
          int_lrs  PLS_INTEGER;
       BEGIN
          -- Step 10
          -- Check over incoming parameters
          IF p_input IS NULL
          THEN
             RETURN NULL;
          END IF;
          -- Step 20
          -- Gather information about the geometry
          int_dims := p_input.get_dims();
          int_gtyp := p_input.get_gtype();
          int_lrs  := p_input.get_lrs_dim();
          -- Step 30
          -- Handle point and multipoint inputs
          IF int_gtyp = 1
          THEN
             RETURN p_input;
          ELSIF int_gtyp = 5
          THEN
             RETURN SDO_UTIL.EXTRACT(p_input,1);
          END IF;
          -- Step 40
          -- Return results
          IF int_dims = 2
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(1)
                ,p_input.SDO_ORDINATES(2)
                ,NULL
                ,NULL
                ,p_input.SDO_SRID
          ELSIF  int_dims = 3
          AND int_lrs = 3
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(1)
                ,p_input.SDO_ORDINATES(2)
                ,NULL
                ,p_input.SDO_ORDINATES(3)
                ,p_input.SDO_SRID
          ELSIF  int_dims = 3
          AND int_lrs = 0
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(1)
                ,p_input.SDO_ORDINATES(2)
                ,p_input.SDO_ORDINATES(3)
                ,NULL
                ,p_input.SDO_SRID
          ELSIF  int_dims = 4
          AND int_lrs IN (4,0)
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(1)
                ,p_input.SDO_ORDINATES(2)
                ,p_input.SDO_ORDINATES(3)
                ,p_input.SDO_ORDINATES(4)
                ,p_input.SDO_SRID
          ELSIF  int_dims = 4
          AND int_lrs = 3
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(1)
                ,p_input.SDO_ORDINATES(2)
                ,p_input.SDO_ORDINATES(4)
                ,p_input.SDO_ORDINATES(3)
                ,p_input.SDO_SRID
          ELSE
             RAISE_APPLICATION_ERROR(-20001,'ERR!');
          END IF;
       END get_start_point;
       FUNCTION get_end_point(
          p_input        IN  MDSYS.SDO_GEOMETRY
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
          int_dims PLS_INTEGER;
          int_gtyp PLS_INTEGER;
          int_lrs  PLS_INTEGER;
          int_len  PLS_INTEGER;
       BEGIN
          -- Step 10
          -- Check over incoming parameters
          IF p_input IS NULL
          THEN
             RETURN NULL;
          END IF;
          -- Step 20
          -- Gather information about the geometry
          int_dims := p_input.get_dims();
          int_gtyp := p_input.get_gtype();
          int_lrs  := p_input.get_lrs_dim();
          int_len  := p_input.SDO_ORDINATES.COUNT();
          -- Step 30
          -- Handle point and multipoint inputs
          IF int_gtyp = 1
          THEN
             RETURN p_input;
          ELSIF int_gtyp = 5
          THEN
             RETURN SDO_UTIL.EXTRACT(
                 p_input
                ,SDO_UTIL.GETNUMELEM(p_input)
          END IF;
          -- Step 40
          -- Return results
          IF int_dims = 2
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(int_len - 1)
                ,p_input.SDO_ORDINATES(int_len)
                ,NULL
                ,NULL
                ,p_input.SDO_SRID
          ELSIF  int_dims = 3
          AND int_lrs = 3
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(int_len - 2)
                ,p_input.SDO_ORDINATES(int_len - 1)
                ,NULL
                ,p_input.SDO_ORDINATES(int_len)
                ,p_input.SDO_SRID
          ELSIF  int_dims = 3
          AND int_lrs = 0
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(int_len - 2)
                ,p_input.SDO_ORDINATES(int_len - 1)
                ,p_input.SDO_ORDINATES(int_len)
                ,NULL
                ,p_input.SDO_SRID
          ELSIF  int_dims = 4
          AND int_lrs IN (4,0)
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(int_len - 3)
                ,p_input.SDO_ORDINATES(int_len - 2)
                ,p_input.SDO_ORDINATES(int_len - 1)
                ,p_input.SDO_ORDINATES(int_len)
                ,p_input.SDO_SRID
          ELSIF  int_dims = 4
          AND int_lrs = 3
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(int_len - 3)
                ,p_input.SDO_ORDINATES(int_len - 2)
                ,p_input.SDO_ORDINATES(int_len)
                ,p_input.SDO_ORDINATES(int_len - 1)
                ,p_input.SDO_SRID
          ELSE
             RAISE_APPLICATION_ERROR(-20001,'ERR!');
          END IF;
       END get_end_point;
       FUNCTION is_spaghetti(
           p_input             IN  MDSYS.SDO_GEOMETRY
          ,p_tolerance         IN  NUMBER DEFAULT 0.05
       ) RETURN VARCHAR2
       AS
          num_tolerance    NUMBER := p_tolerance;
          ary_strings      MDSYS.SDO_GEOMETRY_ARRAY := MDSYS.SDO_GEOMETRY_ARRAY();
          ary_starts       MDSYS.SDO_GEOMETRY_ARRAY := MDSYS.SDO_GEOMETRY_ARRAY();
          ary_ends         MDSYS.SDO_GEOMETRY_ARRAY := MDSYS.SDO_GEOMETRY_ARRAY();
          int_count        PLS_INTEGER;
          ary_start_count  MDSYS.SDO_NUMBER_ARRAY := MDSYS.SDO_NUMBER_ARRAY();
          ary_end_count    MDSYS.SDO_NUMBER_ARRAY := MDSYS.SDO_NUMBER_ARRAY();
          ary_inside_count MDSYS.SDO_NUMBER_ARRAY := MDSYS.SDO_NUMBER_ARRAY();
       BEGIN
          -- Step 10
          -- Check over incoming parameters
          IF p_input IS NULL
          THEN
             RETURN NULL;
          ELSIF p_input.get_gtype = 2
          THEN
             RETURN 'FALSE';
          ELSIF p_input.get_gtype <> 6
          THEN
             RAISE_APPLICATION_ERROR(-20001,'input gtype must be 2 or 6');
          END IF;
          IF num_tolerance IS NULL
          THEN
             num_tolerance := 0.05;
          END IF;
          -- Step 20
          -- Break multistring into single linestrings with nodes
          int_count := SDO_UTIL.GETNUMELEM(p_input);
          ary_strings.EXTEND(int_count);
          ary_starts.EXTEND(int_count);
          ary_ends.EXTEND(int_count);
          ary_start_count.EXTEND(int_count);
          ary_end_count.EXTEND(int_count);
          ary_inside_count.EXTEND(int_count);
          FOR i IN 1 .. int_count
          LOOP
             ary_strings(i) := SDO_UTIL.EXTRACT(p_input,i);
             ary_starts(i)  := get_start_point(ary_strings(i));
             ary_ends(i)    := get_end_point(ary_strings(i));
          END LOOP;
          -- Step 30
          -- Loop through and count the nodes connections
          FOR i IN 1 .. int_count
          LOOP
             ary_start_count(i)  := 0;
             ary_end_count(i)    := 0;
             ary_inside_count(i) := 0;
             FOR j IN 1 .. int_count
             LOOP
                IF i != j
                THEN
                   IF SDO_GEOM.RELATE(
                      ary_starts(i),
                      'DETERMINE',
                      ary_strings(j),
                      num_tolerance
                   ) IN ('TOUCH','CONTAINS','COVERS','ON')
                   THEN
                      ary_start_count(i) := ary_start_count(i) + 1;
                   ELSIF SDO_GEOM.RELATE(
                      ary_ends(i),
                      'DETERMINE',
                      ary_strings(j),
                      num_tolerance
                   ) IN ('TOUCH','CONTAINS','COVERS','ON')
                   THEN
                      ary_end_count(i) := ary_end_count(i) + 1;
                   ELSIF SDO_GEOM.RELATE(
                      ary_strings(i),
                      'DETERMINE',
                      ary_strings(j),
                      num_tolerance
                   ) IN ('TOUCH','CONTAINS','COVERS','OVERLAPBYINTERSECT')
                   THEN
                      ary_inside_count(i) := ary_inside_count(i) + 1;
                   END IF;
                END IF;
             END LOOP;
             IF ary_start_count(i) > 1
             OR ary_end_count(i) > 1
             OR ary_inside_count(i) > 0
             THEN
                RETURN 'TRUE';
             END IF;
          END LOOP;
          RETURN 'FALSE';
       END is_spaghetti;
       FUNCTION points2segment(
           p_point_one              IN  MDSYS.SDO_POINT_TYPE
          ,p_point_two              IN  MDSYS.SDO_POINT_TYPE
          ,p_srid                   IN  NUMBER
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
       BEGIN
          IF ( p_point_one.Z IS NULL AND p_point_two.Z IS NOT NULL )
          OR ( p_point_one.Z IS NOT NULL AND p_point_two.Z IS NULL )
          THEN
             RAISE_APPLICATION_ERROR(
                -20001,
                'both points must have the same number of dimensions, point_one Z is ' ||
                NVL(TO_CHAR(p_point_one.Z),'') ||
                ' and point_two Z is ' ||
                NVL(TO_CHAR(p_point_two.Z),'')
          END IF;
          IF p_point_one.Z IS NULL
          THEN
             RETURN SDO_GEOMETRY(
                 2002
                ,p_srid
                ,NULL
                ,SDO_ELEM_INFO_ARRAY(1,2,1)
                ,SDO_ORDINATE_ARRAY(p_point_one.X,p_point_one.Y,p_point_two.X,p_point_two.Y)
          ELSE
             RETURN SDO_GEOMETRY(
                 3002
                ,p_srid
                ,NULL
                ,SDO_ELEM_INFO_ARRAY(1,2,1)
                ,SDO_ORDINATE_ARRAY(p_point_one.X,p_point_one.Y,p_point_one.Z,p_point_two.X,p_point_two.Y,p_point_two.Z)
          END IF;
       END points2segment;
       FUNCTION points2segment(
           p_point_one              IN  MDSYS.SDO_GEOMETRY
          ,p_point_two              IN  MDSYS.SDO_GEOMETRY
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
          int_gtype1 PLS_INTEGER;
          int_dims1  PLS_INTEGER;
          int_gtype2 PLS_INTEGER;
          int_dims2  PLS_INTEGER;
          point_one  MDSYS.SDO_POINT_TYPE;
          point_two  MDSYS.SDO_POINT_TYPE;
       BEGIN
          int_gtype1 := p_point_one.get_gtype();
          int_dims1  := p_point_one.get_dims();
          int_gtype2 := p_point_two.get_gtype();
          int_dims2  := p_point_two.get_dims();
          IF  int_gtype1 = 1
          AND int_gtype2 = 1
          AND int_dims1  = int_dims2
          AND p_point_one.SDO_SRID = p_point_two.SDO_SRID
          THEN
             NULL;  -- Good
          ELSE
             RAISE_APPLICATION_ERROR(
                 -20001
                ,'both point objects must be points and have the same number of dimensions and SRIDs'
          END IF;
          IF int_dims1 = 4
          THEN
             RETURN SDO_GEOMETRY(
                 4402
                ,p_point_one.SDO_SRID
                ,NULL
                ,SDO_ELEM_INFO_ARRAY(1,2,1)
                ,SDO_ORDINATE_ARRAY(
                     p_point_one.SDO_ORDINATES(1)
                    ,p_point_one.SDO_ORDINATES(2)
                    ,p_point_one.SDO_ORDINATES(3)
                    ,p_point_one.SDO_ORDINATES(4)
                    ,p_point_two.SDO_ORDINATES(1)
                    ,p_point_two.SDO_ORDINATES(2)
                    ,p_point_two.SDO_ORDINATES(3)
                    ,p_point_two.SDO_ORDINATES(4)
          ELSE
             -- Use the sdo_point_type method for the rest
             IF p_point_one.SDO_POINT IS NOT NULL
             THEN
                point_one := p_point_one.SDO_POINT;
             ELSE
                IF int_dims1 = 3
                THEN
                   point_one := SDO_POINT_TYPE(
                       p_point_one.SDO_ORDINATES(1)
                      ,p_point_one.SDO_ORDINATES(2)
                      ,p_point_one.SDO_ORDINATES(3)
                ELSE
                   point_one := SDO_POINT_TYPE(
                       p_point_one.SDO_ORDINATES(1)
                      ,p_point_one.SDO_ORDINATES(2)
                      ,NULL
                END IF;
             END IF;
             IF p_point_two.SDO_POINT IS NOT NULL
             THEN
                point_two := p_point_two.SDO_POINT;
             ELSE
                IF int_dims1 = 3
                THEN
                   point_two := SDO_POINT_TYPE(
                        p_point_two.SDO_ORDINATES(1)
                       ,p_point_two.SDO_ORDINATES(2)
                       ,p_point_two.SDO_ORDINATES(3)
                ELSE
                   point_two := SDO_POINT_TYPE(
                       p_point_two.SDO_ORDINATES(1)
                      ,p_point_two.SDO_ORDINATES(2)
                      ,NULL
                END IF;
             END IF;
             RETURN points2segment(
                 p_point_one   => point_one
                ,p_point_two   => point_two
                ,p_srid        => p_point_one.SDO_SRID
          END IF;
       END points2segment;
       FUNCTION linear_gap_filler(
           p_input            IN  MDSYS.SDO_GEOMETRY
          ,p_tolerance        IN  NUMBER DEFAULT 0.05
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
          sdo_input     MDSYS.SDO_GEOMETRY := p_input;
          num_tolerance NUMBER;
          int_counter   PLS_INTEGER;
          ary_edges     MDSYS.SDO_GEOMETRY_ARRAY;
          ary_starts    MDSYS.SDO_GEOMETRY_ARRAY;
          ary_ends      MDSYS.SDO_GEOMETRY_ARRAY;
          ary_nearest   MDSYS.SDO_NUMBER_ARRAY;
          ary_distance  MDSYS.SDO_NUMBER_ARRAY;
          num_temp      NUMBER;
          num_nearest   NUMBER;
          int_winner    PLS_INTEGER;
          int_winner2   PLS_INTEGER;
          sdo_point1    MDSYS.SDO_GEOMETRY;
          sdo_point2    MDSYS.SDO_GEOMETRY;
          boo_done      BOOLEAN;
          num_one       NUMBER;
          num_two       NUMBER;
          int_looper    PLS_INTEGER := 1;
       BEGIN
          -- Step 10
          -- Check over incoming parameters
          IF num_tolerance IS NULL
          THEN
             num_tolerance := 0.05;
          END IF;
          IF sdo_input IS NULL
          OR sdo_input.get_gtype() <> 6
          THEN
             RETURN sdo_input;
          END IF;
          IF is_spaghetti(sdo_input,p_tolerance) = 'TRUE'
          THEN
             RETURN sdo_input;
          END IF;
          <>      ary_edges     := MDSYS.SDO_GEOMETRY_ARRAY();
          ary_starts    := MDSYS.SDO_GEOMETRY_ARRAY();
          ary_ends      := MDSYS.SDO_GEOMETRY_ARRAY();
          ary_nearest   := MDSYS.SDO_NUMBER_ARRAY();
          ary_distance  := MDSYS.SDO_NUMBER_ARRAY();
          -- Step 20
          -- Break multistring into edges and start and end nodes
          int_counter := SDO_UTIL.GETNUMELEM(sdo_input);     
          ary_edges.EXTEND(int_counter);
          ary_starts.EXTEND(int_counter);
          ary_ends.EXTEND(int_counter);
          FOR i IN 1 .. int_counter
          LOOP 
             ary_edges(i)  := SDO_UTIL.EXTRACT(sdo_input,i);
             ary_starts(i) := get_start_point(ary_edges(i));
             ary_ends(i)   := get_end_point(ary_edges(i));
          END LOOP;
          -- Step 30
          -- Determine the closest endpoints
          ary_nearest.EXTEND(int_counter);
          ary_distance.EXTEND(int_counter);
          FOR i IN 1 .. int_counter
          LOOP
             num_nearest := NULL;
             int_winner := NULL;
             FOR j IN 1 .. int_counter
             LOOP
                IF j != i
                THEN
                   num_temp := SDO_GEOM.SDO_DISTANCE(
                       ary_edges(i)
                      ,ary_edges(j)
                      ,num_tolerance
                   IF num_nearest IS NULL
                   OR num_temp < num_nearest
                   THEN
                      num_nearest := num_temp;
                      int_winner := j;
                   END IF;
                END IF;
             END LOOP;
             ary_nearest(i) := int_winner;
             ary_distance(i) := num_nearest;
          END LOOP;
          -- Step 40
          -- Find the smallest gap
          int_winner := NULL;
          num_nearest := NULL;
          FOR i IN 1 .. int_counter
          LOOP
             IF num_nearest IS NULL
             OR ary_distance(i) < num_nearest
             THEN
                 int_winner := i;
                 num_nearest := ary_distance(i);
                 int_winner2 := ary_nearest(i);
             END IF;
          END LOOP;
          -- Step 50
          -- Determine the endpoints to connect
          num_one := SDO_GEOM.SDO_DISTANCE(
             get_start_point(ary_edges(int_winner)),
             ary_edges(int_winner2),
             num_tolerance
          num_two := SDO_GEOM.SDO_DISTANCE(
             get_end_point(ary_edges(int_winner)),
             ary_edges(int_winner2),
             num_tolerance
          IF ( num_one = 0 AND SDO_GEOM.RELATE(
             get_start_point(ary_edges(int_winner)),
             'ANYINTERACT',
             ary_edges(int_winner2),
             num_tolerance
          ) = 'TRUE' )
          OR ( num_two = 0 AND SDO_GEOM.RELATE(
             get_end_point(ary_edges(int_winner)),
             'ANYINTERACT',
             ary_edges(int_winner2),
             num_tolerance
          ) = 'TRUE' )
          THEN
             sdo_point1 := NULL;
          ELSIF num_one < num_two
          THEN
             sdo_point1 := get_start_point(ary_edges(int_winner));
          ELSE
             sdo_point1 := get_end_point(ary_edges(int_winner));
          END IF;
          num_one := SDO_GEOM.SDO_DISTANCE(
             get_start_point(ary_edges(int_winner2)),
             ary_edges(int_winner),
             num_tolerance
          num_two := SDO_GEOM.SDO_DISTANCE(
             get_end_point(ary_edges(int_winner2)),
             ary_edges(int_winner),
             num_tolerance
          IF ( num_one = 0 AND SDO_GEOM.RELATE(
             get_start_point(ary_edges(int_winner2)),
             'ANYINTERACT',
             ary_edges(int_winner),
             num_tolerance
          ) = 'TRUE' )
          OR ( num_two = 0 AND SDO_GEOM.RELATE(
             get_end_point(ary_edges(int_winner2)),
             'ANYINTERACT',
             ary_edges(int_winner),
             num_tolerance
          ) = 'TRUE' )
          THEN
             sdo_point2 := NULL;
          ELSIF num_one < num_two
          THEN
             sdo_point2 := get_start_point(ary_edges(int_winner2));
          ELSE
             sdo_point2 := get_end_point(ary_edges(int_winner2));
          END IF;
          -- Step 50
          -- Smash together
          IF sdo_point1 IS NULL
          OR sdo_point2 IS NULL
          THEN
             sdo_input := SDO_UTIL.CONCAT_LINES(
                ary_edges(int_winner),
                ary_edges(int_winner2)
          ELSE
             sdo_input := SDO_UTIL.CONCAT_LINES(
                SDO_UTIL.CONCAT_LINES(
                   ary_edges(int_winner),
                   points2segment(sdo_point1,sdo_point2)
                ary_edges(int_winner2)
          END IF;
          boo_done := TRUE;
          FOR i IN 1 .. int_counter
          LOOP
             IF i NOT IN (int_winner,int_winner2)
             THEN
                sdo_input := SDO_UTIL.APPEND(sdo_input,ary_edges(i));
                boo_done := FALSE;
             END IF;
          END LOOP;
          -- Step 60
          -- Check if valid if returning
          IF sdo_input.get_gtype() = 2
          OR boo_done = TRUE
          THEN
             RETURN sdo_input;
          END IF;
          int_looper := int_looper + 1;
          GOTO TOP_OF_IT;
       END linear_gap_filler;
    END dz_gap_fill;

  • Rogue Polygon Hoses various SDO functions

    Hello,
    I have what I think is a fairly reasonable polygon made up of a single ring that has an 13349 error where the polygon closes. I would think I could correct this by unioning the polygon against itself. However, this results in -13050 unable to construct spatial object error.
    Tested on 10.2.0.3 Linux and AIX.
    Furthermore, when I run the polygon through any of the stock "fixers" like REMOVE_DUPLICATE_VERTICES or RECTIFY_GEOMETRY, I get completely whacked out results with the new polygon vertices in a completely different spatial system. If anyone has 11g handy, could you try the code down below? Do you receive back a reasonable polygon?
    SELECT bad_deal FROM dual;
    The polygon I get back is completely different, here are the first three vertices of the strange thing I get back:
    -75.000000000016,44.9999999999196,
    123.640136719051,68.0676269499346,
    -148.066406250019,31.9313049297389
    I would be very hesitant to suggest that anyone run these corrective functions in mass without carefully checking the results.
    Thanks,
    Paul
    CREATE OR REPLACE FUNCTION bad_deal
    RETURN SDO_GEOMETRY
    AS
    baddie SDO_GEOMETRY := SDO_GEOMETRY
    2003,
    8265,
    NULL,
    SDO_ELEM_INFO_ARRAY
    1,
    1003,
    1
    SDO_ORDINATE_ARRAY
    452805, 2454525,
    452823.640136719, 2454591.93237305,
    452911.93359375, 2454628.06869507,
    453030.065917969, 2454715.65673828,
    453045, 2454735,
    453059.157714844, 2454780.84365845,
    453090.842285156, 2454839.15634155,
    453119.157714844, 2454930.84365845,
    453151.303710938, 2455020.43395996,
    453103.315429688, 2455063.31268311,
    453036.342773438, 2455138.26416016,
    453000.842285156, 2455290.84365845,
    452967.385253906, 2455415.77262878,
    452985, 2455665,
    452760.571289063, 2455860.57197571,
    452617.294921875, 2455953.09402466,
    452580.571289063, 2456076.03858948,
    452668.286132813, 2456241.79824829,
    452549.428710938, 2456279.42802429,
    452460.571289063, 2456340.57197571,
    452009.428710938, 2456369.42802429,
    451950.571289063, 2456400.57197571,
    451799.143066406, 2456436.64215088,
    451620.124511719, 2456573.91998291,
    451545, 2456655,
    451410.571289063, 2456760.57197571,
    451202.219238281, 2456883.06060791,
    451023.662109375, 2456875.98335266,
    450870.571289063, 2457000.57197571,
    450659.428710938, 2457029.42802429,
    450442.368164063, 2457118.5861969,
    450312.143554688, 2457049.67697144,
    450180.571289063, 2457150.57197571,
    449999.428710938, 2457179.42802429,
    449835, 2457255,
    449805, 2457255,
    449805, 2457285,
    449775, 2457285,
    449775, 2457315,
    449745, 2457315,
    449745, 2457345,
    449488.337402344, 2457331.65939331,
    449207.709960938, 2457292.1534729,
    448981.662597656, 2457148.34060669,
    448900.297851563, 2457114.05754089,
    448831.662597656, 2457028.34060669,
    448649.816894531, 2456996.69517517,
    448635, 2456745,
    448684.921875, 2456755.078125,
    448801.2890625, 2456812.92114258,
    448815, 2456745,
    449422.075195313, 2456731.48269653,
    449548.06640625, 2456638.06869507,
    449745, 2456625,
    449789.157714844, 2456609.15634155,
    450198.801269531, 2456577.08999634,
    450253.315429688, 2456458.31245422,
    450398.247070313, 2456366.13693237,
    450435, 2456325,
    450570.842285156, 2456339.15634155,
    450689.157714844, 2456370.84365845,
    450877.565917969, 2456400.20347595,
    451058.61328125, 2456498.58581543,
    451194.887695313, 2456436.04042053,
    451544.868164063, 2456130.78987122,
    451746.262207031, 2456038.35777283,
    451799.157714844, 2455979.15634155,
    451846.684570313, 2455936.68754578,
    451962.905273438, 2455806.6142273,
    452061.123046875, 2455761.53457642,
    452100.842285156, 2455650.84365845,
    452133.771972656, 2455369.75364685,
    452249.289550781, 2455289.06364441,
    452336.667480469, 2455294.27139282,
    452489.157714844, 2455169.15634155,
    452662.060546875, 2455128.92715454,
    452705.529785156, 2455007.78274536,
    452697.36328125, 2454870.7585144,
    452751.247558594, 2454822.6159668,
    452789.157714844, 2454539.15634155,
    452805, 2454525
    BEGIN
    RETURN SDO_UTIL.REMOVE_DUPLICATE_VERTICES(baddie,0.05);
    END bad_deal;

    11.1.0.6 on win32 (XP). --DD
    SQL> SELECT bad_deal FROM dual;
    BAD_DEAL(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    SDO_GEOMETRY(2003, 8265, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_ARR
    AY(-75, 45, 123.640137, 68.0676269, -148.06641, 31.9313049, -29.934082, -55.6567
    38, -15, -75, 179.157715, -59.156342, -149.15771, -.84365845, 59.1577148, 89.156
    3415, 91.3037109, -.43395996, 43.3154297, -43.312683, 156.342773, -61.73584, -59
    .157715, 89.1563416, -92.614746, -35.772629, -75, 75, -119.42871, -59.428024, 97
    .2949219, 33.0940247, -119.42871, 23.9614105, 148.286133, -38.201752, 29.4287109
    , -.57197571, -59.428711, 60.5719757, -150.57129, 89.4280243, -29.428711, 59.428
    0243, 179.143066, 23.3578491, -179.87549, -66.080017, 105, 15, 150.571289, 59.42
    80243, -57.780762, -63.060608, 123.662109, -55.983353, 150.571289, .57197571, -6
    0.571289, 29.4280243, -97.631836, 61.4138031, -47.856445, 49.6769714, .571289063
    , 29.4280243, 179.428711, .57197571, 15, -75, -15, -75, 165, -75, 135, -75, 135,
    BAD_DEAL(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    -45, 105, -45, 105, -15, -151.6626, -28.340607, -72.290039, -67.846527, -118.33
    74, 31.6593933, 160.297852, 65.9424591, -88.337402, 28.3406067, 89.8168945, -3.3
    048248, -105, 75, -55.078125, 64.921875, 61.2890625, 7.07885742, 75, 75, -37.924
    805, 88.5173035, -91.933594, -1.9313049, 105, -15, 149.157715, -30.843658, -161.
    19873, -62.910004, 73.3154297, 1.68754578, 38.2470703, 86.1369324, 75, 45, -149.
    15771, 59.1563416, 149.157715, 89.1563416, -22.434082, 59.7965241, 158.613281, -
    38.585815, -65.112305, 23.9595795, -75.131836, -30.789871, 126.262207, 61.642227
    2, -.84228516, 59.1563415, 46.6845703, 16.6875458, -17.094727, -66.614227, 81.12
    30469, -21.534576, 120.842285, 89.1563415, 153.771973, 10.2463532, 89.2895508, 8
    9.0636444, -3.3325195, 85.7286072, -30.842285, -30.843658, 142.060547, -71.07284
    5, 5.52978516, 12.2172546, 177.363281, 30.7585144, -128.75244, -17.384033, -90.8
    BAD_DEAL(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    42285, 59.1563416, -75, 45))

  • Format of VALIDATE_GEOMETRY_WITH_CONTEXT output

    Hi,
    I'm trying to write a generic routine to display validation errors (e.g. show the geometry with the erroneous segments highlighted), with the aim to more easily correct them.
    What I am wondering is, is there are documentation on the format of the context information output by VALIDATE_GEOMETRY_WITH_CONTEXT, as there are several outputs produced
    e.g.
    13356 [Element <1>] [Coordinate <4>][Ring <1>]
    13349 [Element <1>] [Ring <1>][Edge <6>][Edge <21>]
    I can decipher these specific errors, but a definitive reference would be appreciated.
    thanks in advance,
    Andrew

    Hi Andrew,
    I know this is hard, but it is a great improvement from earlier, when Oracle didn't report any location information.
    The reference for the numbers (13356 or 13349) is the error messages documentation.
    ORA-13349: polygon boundary crosses itself
    Cause: The boundary of a polygon intersects itself.
    Action: Correct the geometric definition of the object.
    ORA-13356: adjacent points in a geometry are redundant
    Cause: There are repeated points in the sequence of coordinates.
    Action: Remove the redundant point.
    The rest of the information is an attempt to help you locate where in the geometry the problem was found.
    13356 [Element <1>] [Coordinate <4>][Ring <1>]
    The first element in SDO_ORDINATE array is the one with the problem
    The 4th vertex is a duplicate of the 5th vertex (falls within the specified tolerance so the two coordinates are considered the same).
    Ring 1 - The first element is a polygon, and a single polygon can consist of an exterior ring with one or more holes (interior rings). Since this is ring 1, it is the exterior ring associated with the first element. If it was Ring 2, it would be the first hole, ring 3 would be the second hole, and so on.
    13349 [Element <1>] [Ring <1>][Edge <6>][Edge <21>]
    With this error the first ring (exterior ring) of the first element in the sdo_ordinate_array has edges that self intersect. The edges are edge 6 and edge 21. The edges can be identifed as the 6th and 7th vertices (edge 6) and the 21st and 22nd vertices.
    You can use sdo_util.get_vertices to look at coordinate pairs.
    There is also sdo_util.remove_duplicate_vertices to get rid of the duplicate vertex errors.
    Sometimes I union a geometry with itself to see if Oracle can fix an invalid polygon whose edges intersect (this isn't guaranteed to work because operations on invalid geometries aren't supported), but if it succeeds I look at the input and output geometries together and if I am convinced they are the same then I put the new geometry back into the table.
    Hope this helps,
    Dan

  • How to resolve VALIDATE_GEOMETRY_WITH_CONTEXT 'errors'?

    Hello,
    I have some problem to select my spatial data (see Result of sdo_within_distance ). Sometime I select data and my database connection will be separated (ORA-03113, ORA-03114).
    Now I try to analys my data with VALIDATE_GEOMETRY_WITH CONTEXT:
    SELECT c.SPA_CODE, SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(c.GEOM, 0.5)
    FROM protection_area.sk_2006_spa c
    WHERE SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(c.GEOM, 0.5)<>'TRUE'
    ORDER BY c.SPA_CODE
    Here a part of the result:
    1     SKCHVU002     13348 [Element <1>] [Ring <2>]
    2     SKCHVU003     13349 [Element <1>] [Ring <1>][Edge <5247>][Edge <5252>]
    3     SKCHVU004     13367 [Element <5>] [Ring <1>]
    4     SKCHVU009     13348 [Element <1>] [Ring <14>]
    5     SKCHVU010     13348 [Element <2>] [Ring <1>]
    6     SKCHVU013     13348 [Element <1>] [Ring <8>]
    7     SKCHVU015     13348 [Element <6>] [Ring <7>]
    8     SKCHVU016     13349 [Element <3>] [Ring <1>][Edge <2175>][Edge <2178>]
    9     SKCHVU017     13367 [Element <5>] [Ring <2>]
    10     SKCHVU018     13349 [Element <9>] [Ring <1>][Edge <5368>][Edge <5370>]
    11     SKCHVU019     13348 [Element <14>] [Ring <29>]
    12     SKCHVU021     13367 [Element <1>] [Ring <1>]
    13     SKCHVU025     13367 [Element <1>] [Ring <13>]
    What can I do to avoid this 'errors'?
    I already tried this:
    UPDATE protection_area.sk_2006_spa c
    SET c.GEOM = SDO_UTIL.REMOVE_DUPLICATE_VERTICES(c.geom,0.5)
    Any hints?
    Thanks,
    matthias

    Hi,
    You need to correct those geometries.
    I've got this from Oracle Spatial 10g User's Guide:
    Rings: A ring is only used with polygon elements. Exterior rings in a polygon are
    considered polygon elements, and an exterior ring can include zero or more
    interior rings (or holes). Each interior ring has its own ring designation, but Ring 1
    is associated with the exterior polygon itself. For example, Element 1, Ring 1 refers to the first exterior polygon in a geometry; Element 1, Ring 2 refers to the first interior polygon of the first exterior polygon; and Element 1, Ring 3 refers to the second interior polygon. If the geometry is a multipolygon, Element 2, Ring 1 is
    used to refers to the second exterior polygon. If there are interior polygons
    associated with it, Element 2, Ring 2 refers to the first interior polygon of the
    second exterior polygon.
    Edges: An edge refers to a line segment between two coordinates. Edge 1 refers to the segment between coordinate 1 and coordinate 2, Edge 2 refers to the line segment between coordinates 2 and 3, and so on. The most common place to see edge errors when validating geometries is with self-intersecting polygons. (The Open Geospatial Consortium simple features specification does not allow a
    polygon to self-intersect.) In such cases, Oracle reports error 13349 (polygon
    boundary crosses itself), including the Element, Ring, and Edge numbers where
    self-intersection occurs.
    Hope it helps,
    Luiz

  • SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT giving seemingly incorrect result

    I ran the following query and got the unexpected answer of TRUE:
    SELECT SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT
    SDO_UTIL.REMOVE_DUPLICATES
    SDO_GEOMETRY
    2002,
    8307,
    NULL,
    SDO_ELEM_INFO_ARRAY(1,2,1),
    SDO_ORDINATE_ARRAY(32.5, 65.789, 32.5, 65.789)
    ), .005
    ), .005
    FROM dual;
    What surprised me was the SDO_ORDINATE_ARRAY after the remove duplicates has only a longitude and latitude yet the geometry a line was validated as true. Doesn't a line at least need two sets of coordinates? How was this geometry validated to true?

    yet the geometry a line was validated as true.Actually a geometry line containing duplicates was converted to a point type (gtype 2001), which was validated as 'TRUE' as it should be.
    SQL> SELECT SDO_UTIL.REMOVE_DUPLICATE_VERTICES(SDO_GEOMETRY(2003, 8307,NULL,
    SDO_ELEM_INFO_ARRAY(1,1003,1),
    SDO_ORDINATE_ARRAY(32.5, 65.789, 32.5, 65.789)
    ),0.005)
    FROM DUAL;
    SDO_GEOMETRY(2001, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 1, 1), SDO_ORDINATE_ARRAY(32.5, 65.789))
    1 row selected.

  • Sdo_aggr_union error

    Hi
    Im trying to union some geometies and get the error message below.
    I know in this example 2 of the 3 geometries are invalid with 13356 duplicate vertices problems.
    However I cant correct this easily as SDO_UTIL.REMOVE_DUPLICATE_VERTICES is not available to me on 9.2.0.3.0.
    In any case, I have been able to union invalid geometries before, any ideas why my database has just started to complain?
    I have tried different tolerance levels with no success.
    Many Thanks
    Richard
    SQL> select sdo_aggr_union(MDSYS.SDOAGGRTYPE(geoloc,0.5)) geoloc
    2 from mytable where id = 1002370
    3 /
    select sdo_aggr_union(MDSYS.SDOAGGRTYPE(geoloc,0.5)) geoloc
    ERROR at line 1:
    ORA-00600: internal error code, arguments: [kohdtf048], [], [], [], [], [], [], []
    ORA-06512: at "MDSYS.AGGRUNION", line 25
    ORA-06512: at "MDSYS.AGGRUNION", line 25
    ORA-06512: at line 1

    Richard,
    When the data is invalid, there is no easy way to tell why it is not working.
    Can you try the union at a smaller tolerance ?
    siva

  • Fixing Geometry Errors

    Has anyone put together a list of "x error can be fixed by doing y" for geometry errors?
    I ask this because I am in the middle of writting code to fix geometry errors within a database from imported ESRI-based data. Presently I have the code to find all errors, and can fix:
    13349 and 13366
    Fix with a self union (same geometry twice): SDO_GEOM.SDO_UNION
    13356
    Fix with the new SDO_UTIL.REMOVE_DUPLICATE_VERTICES function.
    I started with these, since they are most pervasive.
    Obviously, some errors like 13351 and 13350 are harder, since the code actually needs to slightly alter the original data (move the rings or touching points) to remove the errors.

    Bryan,
    I have a ShapeCheck routine in PL/SQL that I have deployed in the past databases as a dbms_job...
    I have a number of versions depending on how you want the errors to be reported: one via SMTP_UTL for emailing, another writes answers to a table for visualisation with Application Express.
    If you want a copy email me at simon at spatialdbadvisor dot com
    Or.... here it is...
    DEFINE defaultSchema='&1'
    set serverout on SIZE 1000000
    DROP PROCEDURE ShapeCheck;
    DROP TABLE ALL_FEATURE_ERROR;
    CREATE TABLE ALL_FEATURE_ERROR (
    owner VARCHAR2(30),
    table_name VARCHAR2(30),
    column_name VARCHAR2(30),
    feature_rowid VARCHAR2(20),
    error_code VARCHAR2(10),
    error_status CHAR(1),
    error_context VARCHAR2(2000),
    error_date DATE
    grant insert,update,delete,select on all_feature_error to public;
    CREATE PROCEDURE ShapeCheck( p_schema IN VARCHAR2,
    p_tableName IN VARCHAR2,
    p_shapeName IN VARCHAR2,
    p_whereClause IN VARCHAR2)
    AUTHID CURRENT_USER
    IS
    v_shape MDSYS.SDO_GEOMETRY;
    c_shape MDSYS.SDO_GEOMETRY;
    v_OwnerName VARCHAR2(30);
    v_TableName VARCHAR2(30);
    v_ColumnName VARCHAR2(30);
    c_rowid ROWID;
    v_error_code ALL_FEATURE_ERROR.ERROR_CODE%TYPE;
    v_error_status ALL_FEATURE_ERROR.ERROR_STATUS%TYPE;
    v_error_context ALL_FEATURE_ERROR.ERROR_CONTEXT%TYPE;
    v_error_count number;
    v_error_found number;
    v_fixed_count number;
    v_count number;
    v_diminfo MDSYS.SDO_DIM_ARRAY;
    v_start_date DATE;
    v_end_date DATE;
    v_tolerance number;
    v_query varchar2(1024);
    TYPE shapeCursorType IS REF CURSOR;
    shapeCursor shapeCursorType;
    BEGIN
    v_TableName := UPPER(p_tablename);
    v_OwnerName := UPPER(p_schema);
    v_ColumnName := UPPER(p_ShapeName);
    BEGIN -- In case get NO_DATA_FOUND
    SELECT diminfo
    INTO v_diminfo
    FROM ALL_SDO_GEOM_METADATA
    WHERE owner = v_OwnerName and table_name = v_TableName and column_name = v_ColumnName;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    dbms_output.put_line('No diminfo found in all_sdo_geom_metadata for '||v_OwnerName||'.'||v_TableName||'.'||v_ColumnName);
    RETURN;
    END;
    v_tolerance := v_diminfo(1).sdo_tolerance;
    v_count := 0;
    v_error_count := 0;
    v_fixed_count := 0;
    IF ( p_whereClause is not null ) THEN
    v_query := 'SELECT ROWID,' ||v_ColumnName|| ' FROM ' ||v_OwnerName|| '.' ||v_TableName|| ' WHERE ' ||p_whereClause;
    ELSE
    v_query := 'SELECT ROWID,' ||v_ColumnName|| ' FROM ' ||v_OwnerName|| '.' ||v_TableName;
    END IF;
    v_start_date := SYSDATE;
    OPEN shapeCursor
    FOR v_query;
    LOOP
    FETCH shapeCursor INTO c_rowid, c_shape;
    EXIT WHEN shapeCursor%NOTFOUND;
    IF ( c_shape IS NULL ) THEN
    v_error_code := 'NULL';
    ELSE
    v_error_code := SUBSTR(MDSYS.SDO_GEOM.VALIDATE_GEOMETRY( c_shape, v_diminfo ),1,5);
    END IF;
    IF ( v_error_code <> 'TRUE' ) THEN
    v_error_count := v_error_count + 1;
    v_error_status := 'E'; -- if exception raised in following block this will remain 'E'
    IF ( v_error_code <> 'NULL' ) THEN
    BEGIN -- Exception block in case any of the functions trying to fix the shape fail...
    IF ( v_error_code = '13356' ) THEN
    v_shape := mdsys.sdo_util.remove_duplicate_vertices(c_shape,v_tolerance);
    ELSIF c_shape.sdo_gtype in (2003,3007) THEN -- only try to fix bad polygons
    v_shape := mdsys.sdo_geom.sdo_union(c_shape,v_diminfo,c_shape,v_diminfo);
    IF ( v_shape.sdo_gtype = 2004 ) THEN
    v_shape := &&defaultSchema..geom.ExtractPolygon(v_shape);
    END IF;
    END IF;
    -- Update shape to reflect whatever happened...
    EXECUTE IMMEDIATE 'UPDATE ' || v_OwnerName||'.'||v_TableName || ' A SET A.'||v_ColumnName||' = :1 WHERE rowid = :2 '
    USING v_shape,c_rowid;
    -- Check whether it was corrected or not...
    v_error_context := SUBSTR(MDSYS.SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(v_shape,v_diminfo),1,2000);
    v_error_code := SUBSTR(v_error_context,1,5);
    v_error_context := SUBSTR(v_error_context,6,2000);
    IF v_error_code = 'TRUE' THEN
    v_error_status := 'F';
    v_fixed_count := v_fixed_count + 1;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    NULL;
    END;
    END IF; -- v_error_code = NULL
    INSERT INTO &&defaultSchema..All_Feature_Error(owner,table_name,column_name,feature_rowid,error_code,error_status,error_context,error_date) VALUES (v_OwnerName,v_TableName,v_ColumnName,c_rowid,v_error_code,v_error_status,v_error_context,SYSDATE);
    END IF;
    END LOOP;
    v_count := shapeCursor%ROWCOUNT;
    CLOSE shapeCursor;
    v_end_date := SYSDATE;
    dbms_output.put_line('SHAPECHECK SUMMARY.');
    dbms_output.put_line(' TABLE: ' || v_OwnerName||'.'||v_TableName||'.'||v_ColumnName);
    dbms_output.put_line(' PROCESSING START: ' || to_char(v_start_date,'YYYY-MM-DD HH24:MM') );
    dbms_output.put_line(' PROCESSING END: ' || to_char(v_end_date,'YYYY-MM-DD HH24:MM') );
    dbms_output.put_line('FEATURES PROCESSED: ' || to_char(v_count) );
    dbms_output.put_line('TOTAL ERRORS FOUND: ' || to_char(v_error_count) );
    dbms_output.put_line('TOTAL ERRORS FIXED: ' || to_char(v_fixed_count) );
    dbms_output.put_line('See table ALL_FEATURE_ERROR for list of errors');
    END ShapeCheck;
    show errors
    grant execute on &&defaultSchema..ShapeCheck to public;
    -- connect radtrain4@radtrain4@sdb1test
    -- execute &&defaultSchema..shapecheck('RADTRAIN4','AB_LANDCLAIM','GEOMETRY',NULL);
    -- VARIABLE jobno number;
    -- BEGIN
    -- DBMS_JOB.SUBMIT(:jobno,'&&defaultSchema..shapecheck(''RADTRAIN4'',''SP_PARCEL'',''GEOMETRY'',NULL)'',''[email protected],[email protected]'' );',SYSDATE,'next_day(sysdate,''SUNDAY'')' );
    -- COMMIT;
    -- END;
    --

  • SDO_UTIL Missing Functions?

    Folks,
    I am accessing a 10.2.0.1 SE database at a client site and when I describe the SDO_UTIL package I don't get all the functions in 10.2.0.1 that I use when developing my PL/SQL packages (for download at my website).
    SQL*Plus: Release 10.2.0.1.0 - Production on Fri Feb 9 09:06:27 2007
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Release 10.2.0.1.0 - 64bit Production
    SQL> desc sdo_util
    FUNCTION APPEND RETURNS SDO_GEOMETRY
    Argument Name Type In/Out Default?
    GEOMETRY1 SDO_GEOMETRY IN
    GEOMETRY2 SDO_GEOMETRY IN
    FUNCTION EXTRACT RETURNS SDO_GEOMETRY
    Argument Name Type In/Out Default?
    GEOMETRY SDO_GEOMETRY IN
    ELEMENT NUMBER IN
    RING NUMBER IN DEFAULT
    FUNCTION GETVERTICES RETURNS VERTEX_SET_TYPE
    Argument Name Type In/Out Default?
    GEOMETRY SDO_GEOMETRY IN
    FUNCTION REMOVE_DUPLICATES RETURNS SDO_GEOMETRY
    Argument Name Type In/Out Default?
    GEOMETRY SDO_GEOMETRY IN
    DIM SDO_DIM_ARRAY IN
    FUNCTION REMOVE_DUPLICATE_VERTICES RETURNS SDO_GEOMETRY
    Argument Name Type In/Out Default?
    GEOMETRY SDO_GEOMETRY IN
    TOLERANCE NUMBER IN
    FUNCTION TRUNCATE_NUMBER RETURNS NUMBER
    Argument Name Type In/Out Default?
    VALUE NUMBER IN
    NO_OF_DIGITS NUMBER IN
    In particular, I am looking for CONCAT_LINES() and RECTIFY_GEOMETRY.
    Any pointers?
    regards
    Simon Greener

    Dan,
    This explains it. I am running 10.2.0.1 on my laptop and have all the functions etc.
    I have seen this error:
    ORA-04063: type body "MDSYS.SDO_INDEX_METHOD_9I" has errors
    at many sites but never quite got to the bottom as to why it occurred was occuring on 10g databases! I always assumed the _9I thing was a short term carry over.
    Now I know!
    Mate, I am really well. Thankfully, reasonably busy, though things were a bit quiet when I got back from Europe (last October). It was great to meet you though it would have been nice to have had a chance to catch up over a drink/dinner but you had to fly back to the USA. I have started down the OCP track which, on top of everything else, is keeping me out of mischief!
    I hope all is going well with you. We should drop each other an email off line...
    regards
    S

  • Errors in sdo_util on 12c

    I have installed spatial on an Oracle 12C database and I am receiving the error below when using sdo_util.to_wktgeometry. Some of the other sdo_util functions work as expected. I checked the class files and they are all valid. Has anyone else encountered this error.
    ORA-29531: no method structToWktJS in class oracle/spatial/util/Adapters
    ORA-06512: at "MDSYS.SDO_JAVA_STP", line 350
    ORA-06512: at "MDSYS.SDO_UTIL", line 2813
    ORA-06512: at "MDSYS.SDO_UTIL", line 2836
    29531. 00000 -  "no method %s in class %s"
    *Cause:    An attempt was made to execute a non-existent method in a
               Java class.
    *Action:   Adjust the call or create the specified method.

    I am not getting any error, as shown below, using a few excerpts from the online documentation.  Can you run the same or similar script without error?  Can you post a run of a test case that does produce the error for you?
    SCOTT@orcl12c> set long 2000;
    SCOTT@orcl12c> SELECT banner FROM v$version;
    BANNER
    Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
    PL/SQL Release 12.1.0.1.0 - Production
    CORE    12.1.0.1.0    Production
    TNS for 64-bit Windows: Version 12.1.0.1.0 - Production
    NLSRTL Version 12.1.0.1.0 - Production
    5 rows selected.
    SCOTT@orcl12c> CREATE TABLE cola_markets
      2    (mkt_id    NUMBER PRIMARY KEY,
      3      name    VARCHAR2(32),
      4      shape    SDO_GEOMETRY);
    Table created.
    SCOTT@orcl12c> INSERT INTO cola_markets VALUES
      2    (2, 'cola_b',
      3      SDO_GEOMETRY
      4        (2003, NULL, NULL,
      5         SDO_ELEM_INFO_ARRAY (1,1003,1),
      6         SDO_ORDINATE_ARRAY(5,1, 8,1, 8,6, 5,7, 5,1)));
    1 row created.
    SCOTT@orcl12c> INSERT INTO user_sdo_geom_metadata (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES
      2    ('cola_markets', 'shape',
      3      SDO_DIM_ARRAY
      4        (SDO_DIM_ELEMENT('X', 0, 20, 0.005),
      5         SDO_DIM_ELEMENT('Y', 0, 20, 0.005)),
      6      NULL);
    1 row created.
    SCOTT@orcl12c> CREATE INDEX cola_spatial_idx ON cola_markets(shape) INDEXTYPE IS MDSYS.SPATIAL_INDEX;
    Index created.
    SCOTT@orcl12c> SELECT SDO_UTIL.TO_WKTGEOMETRY (shape) FROM cola_markets WHERE name = 'cola_b';
    SDO_UTIL.TO_WKTGEOMETRY(SHAPE)
    POLYGON ((5.0 1.0, 8.0 1.0, 8.0 6.0, 5.0 7.0, 5.0 1.0))
    1 row selected.

  • Using SDO_UTIL.GETVERTICES() together with functions

    Hi again
    I'm having a problem here in my spatial database I trying to use the function
    TABLE(SDO_UTIL.GETVERTICES(c.shape)) in order to get the coordinates of shapes. But I need to first extract data from spatial functions like the centroid function. How do I get these 2 functions to work together.
    thanks very much
    Thomaz

    Hi Thomaz,
    Maybe I missed your point, but what about the following:
    select t.y, t.x, t.id
    from your_geom_table,
    table(
    sdo_util.GETVERTICES(
    sdo_geom.sdo_centroid(geom, 0.005)
    ) t
    regards,
    Thomas

  • SDO_UTIL.PREPARE_FOR_TTS

    I'm using this procedure as documented prior to exporting my metadata in preparation of transporting a tablespace to another database. I noticed that after this procedure is run, there is an addition parameter listed in the parameters column of ALL_INDEXES: TTS_TABLE=SDO_INDEX_TTS_METADATA$
    If I run this procedure multiple times, as if I were going to transport this tablespace to yet another database, it placed yet another TTS_TABLE=SDO_INDEX_TTS_METADATA$ into the parameters column.
    Does anyone out there know if this is a problem. Should I open a TAR on this problem.
    I will be doing this at least 5 times (setting of 5 replica's of a master site) prior to turning on Advanced Replication.

    Hi Paul,
    I'm looking forward to hearing you work the term "fancy hat" into an explanation of this behavior.
    I get the same behavior on 11.2.0.2. Tsk tsk on you for not mentioning your version. Back on 10.2.0.4 the same select statements yield:
    ORA-06531: Reference to uninitialized collection
    ORA-06512: at "MDSYS.SDO_UTIL", line 344
    So the only nuance I can think of, which isn't really a nuance at all, is that getnumvertices isn't allowed for point types.
    Matt

Maybe you are looking for