-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGETJSONGEOMETRYRINGS.sql
More file actions
74 lines (61 loc) · 2.31 KB
/
GETJSONGEOMETRYRINGS.sql
File metadata and controls
74 lines (61 loc) · 2.31 KB
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
create or replace
FUNCTION getJSONGeometryRings(in_POLYGON in sde.ST_Geometry) return clob as
v_clob CLOB;
v_vc varchar2(32000);
v_ring sde.ST_Linestring;
numpoints int;
v_numinteriorrings int;
temppoint sde.ST_Point;
v_x number;
v_y number;
procedure app(v_clob in out nocopy clob, v_vc in out nocopy varchar2, v_app varchar2) is
begin
v_vc := v_vc || v_app;
exception when VALUE_ERROR then
dbms_lob.append(v_clob, v_vc);
v_vc := v_app;
end;
function point2Char(in_point sde.ST_Point) return varchar2 as
begin
select sde.st_X(in_point), sde.ST_Y(in_point) into v_x, v_y from dual;
return '[' || to_char(v_x,'fm9999999.999999') || ',' || to_char(v_y,'fm9999999.999999') || ']' || chr(10);
end;
Begin
/* Exterior ring first */
select sde.st_ExteriorRing(in_Polygon) into v_ring from dual;
select sde.st_numpoints(v_ring) into numpoints from dual;
--dbms_output.put_line(numpoints);
v_clob := '[' || CHR(10);
for point in 1..(numpoints-1) Loop
select sde.st_pointn(v_ring, point) into temppoint from dual;
app(v_clob, v_vc, point2char(temppoint) || ',');
end loop;
/* Final point and closing bracket */
select sde.st_pointn(v_ring, numpoints) into temppoint from dual;
app(v_clob, v_vc, point2char(temppoint) || ']');
-- Interior rings
select sde.st_NumInteriorRing(in_polygon) into v_numinteriorrings from dual;
if v_numinteriorrings > 0 then
app(v_clob, v_vc, ',' || chr(10) );
for ring in 1..v_numinteriorrings Loop --ring 0 is the exterior ring so we start with 1
app(v_clob, v_vc, '[' );
select sde.st_InteriorRingN(in_polygon, ring) into v_ring from dual;
select sde.st_numpoints(v_ring) into numpoints from dual;
for point in 1..(numpoints-1) Loop
select sde.st_pointn(v_ring, point) into temppoint from dual;
app(v_clob, v_vc, point2char(temppoint) || ',');
end loop;
dbms_output.put_line('Ring ' || ring || ', number of rings: ' || v_numinteriorrings);
/* Final point and closing bracket */
select sde.st_pointn(v_ring, numpoints) into temppoint from dual;
app(v_clob, v_vc, point2char(temppoint) || ']');
--v_clob := v_clob || v_vc;
if ring <> v_numinteriorrings then
app(v_clob, v_vc, ',');
end if;
End Loop;
end if;
-- Anything left over
v_clob := v_clob || v_vc;
return v_clob;
end;