Trying to optimize a procedure that parses GML strings to Oracle sdo_geometry.
<gml:Polygon >
<gml:exterior>
<gml:LinearRing>
<gml:posList > [coordinates] </gml:posList>
</gml:LinearRing>
</gml:exterior>
<gml:interior>
<gml:Ring>
<gml:curveMember>
<gml:Curve>
<gml:segments>
<gml:LineStringSegment>
<gml:posList > [coordinates] </gml:posList>
</gml:LineStringSegment>
<gml:Arc>
<gml:posList > [coordinates] </gml:posList>
</gml:Arc>
<gml:LineStringSegment>
<gml:posList > ... </gml:posList>
</gml:LineStringSegment>
</gml:segments>
</gml:Curve>
</gml:curveMember>
</gml:Ring>
</gml:interior>
<gml:interior>
<gml:LinearRing>
<gml:posList > [coordinates] </gml:posList>
</gml:LinearRing>
</gml:interior>
</gml:Polygon>
The polygon consists of 1 exterior and 0-many interior elements.
Our current solution works as follows.
First it extracts all exterior and interior elements and processes those separately
cursor c_exterior(p_xml xmltype) is
select t.*
from xmltable('//exterior' passing p_xml columns exterior xmltype path '/') as t;
cursor c_interior(p_xml xmltype) is
select t.*
from xmltable('//interior' passing p_xml columns interior xmltype path '/') as t;
begin
-- process each exterior/interior ring.
for r_exterior in c_exterior(p_xml)
loop
process(r_exterior.exterior, [other params]);
end loop;
for r_interior in c_interior(p_xml)
loop
process(r_interior.interior, [other params]);
end loop;
The processing of the exterior and interior element is as follows:
select t.*
from xmltable('for $d in //node() where exists($d/posList) return $d' passing p_xml columns
poslist clob path './posList'
,parent varchar2(100) path 'name()') as t;
This gets the list of coordinates and the name of the immediate parent of the poslist element.
Question: Since this is a two step process it may not be optimized for speed. I'm looking for ways to get the information I need from the GML in 1 query. But I can't figure out how to do that. Mainly because of the varying level into the XML of the poslist element and generating the number of the exterior/interior ring.
Information I need:
- exterior or interior.
- Number of ring. So I know the coordinates are part of the same exterior/interior ring.
- The [coordinates]
- Name of immediate parent of the poslist element.
So from above example:
exterior, 1, gml:LinearRing, [coordinates]
interior, 2, gml:LineStringSegment, [coordinates]
interior, 2, gml:Arc, [coordinates]
interior, 2, gml:LineStringSegment, [coordinates]
interior, 3, gml:LinearRing, [coordinates]