35.78 SDO_UTIL.TO_GMLGEOMETRY
Format
SDO_UTIL.TO_GMLGEOMETRY( geometry IN SDO_GEOMETRY ) RETURN CLOB;
or
SDO_UTIL.TO_GML311GEOMETRY( geometry IN SDO_GEOMETRY, coordOrder IN NUMBER ) RETURN CLOB;
Description
Converts a Spatial geometry object to a geography markup language (GML 2.0) fragment based on the geometry types defined in the Open GIS geometry.xsd
schema document.
Parameters
Usage Notes
Note:
The SDO_UTIL.TO_GMLGEOMETRY function is supported only if Oracle JVM is enabled on your Oracle Autonomous Database Serverless deployments. To enable Oracle JVM, see Use Oracle Java in Using Oracle Autonomous Database Serverless for more information.This function does not convert circles, geometries containing any circular arcs, LRS geometries, or geometries with an SDO_ETYPE value of 0 (type 0 elements); it returns an empty CLOB in these cases.
This function converts the input geometry to a GML fragment based on some GML geometry types defined in the Open GIS Implementation Specification.
Polygons must be defined using the conventions for Oracle9i and later releases of Spatial. That is, the outer boundary is stored first (with ETYPE=1003) followed by zero or more inner boundary elements (ETYPE=2003). For a polygon with holes, the outer boundary must be stored first in the SDO_ORDINATES definition, followed by coordinates of the inner boundaries.
LRS geometries must be converted to standard geometries (using the SDO_LRS.CONVERT_TO_STD_GEOM or SDO_LRS.CONVERT_TO_STD_LAYER function) before being passed to the TO_GMLGEOMETRY function. (See the Examples section for an example that uses CONVERT_TO_STD_GEOM with the TO_GMLGEOMETRY function.)
Any circular arcs or circles must be densified (using the SDO_GEOM.SDO_ARC_DENSIFY function) or represented as polygons (using the SDO_GEOM.SDO_BUFFER function) before being passed to the TO_GMLGEOMETRY function. (See the Examples section for an example that uses SDO_ARC_DENSIFY with the TO_GMLGEOMETRY function.)
Label points are discarded. That is, if a geometry has a value for the SDO_POINT field and values in SDO_ELEM_INFO and SDO_ORDINATES, the SDO_POINT is not output in the GML fragment.
The SDO_SRID value is output in the form srsName="SDO:<srid>"
. For example, "SDO:8307"
indicates SDO_SRID 8307, and "SDO:"
indicates a null SDO_SRID value. No checks are made for the validity or consistency of the SDO_SRID value. For example, the value is not checked to see if it exists in the MDSYS.CS_SRS table or if it conflicts with the SRID value for the layer in the USER_SDO_GEOM_METADATA view.
Coordinates are always output using the <coordinates>
tag and decimal='.'
, cs=','
(that is, with the comma as the coordinate separator), and ts=' '
(that is, with a space as the tuple separator), even if the NLS_NUMERIC_CHARACTERS setting has ','
(comma) as the decimal character.
The GML output is not formatted; there are no line breaks or indentation of tags. To see the contents of the returned CLOB in SQL*Plus, use the TO_CHAR() function or set the SQL*Plus parameter LONG to a suitable value (for example, SET LONG 40000
). To get formatted GML output or to use the return value of TO_GMLGEOMETRY in SQLX or Oracle XML DB functions such as XMLELEMENT, use the XMLTYPE(clobval CLOB) constructor.
Examples
The following example returns the GML fragment for the cola_b
geometry in the COLA_MARKETS table. (The example uses the definitions and data from Simple Example: Inserting_ Indexing_ and Querying Spatial Data.)
-- Convert cola_b geometry to GML fragment. SELECT TO_CHAR(SDO_UTIL.TO_GMLGEOMETRY(shape)) AS GmlGeometry FROM COLA_MARKETS c WHERE c.name = 'cola_b'; GMLGEOMETRY -------------------------------------------------------------------------------- <gml:Polygon srsName="SDO:" xmlns:gml="http://www.opengis.net/gml"><gml:outerBou ndaryIs><gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">5,1 8,1 8,6 5 ,7 5,1 </gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>
The following example returns the GML fragment for the arc densification of the cola_d
geometry in the COLA_MARKETS table. (The example uses the definitions and data from Simple Example: Inserting_ Indexing_ and Querying Spatial Data.)
SET LONG 40000 SELECT XMLTYPE(SDO_UTIL.TO_GMLGEOMETRY( SDO_GEOM.SDO_ARC_DENSIFY(c.shape, m.diminfo, 'arc_tolerance=0.05'))) AS GmlGeometry FROM cola_markets c, user_sdo_geom_metadata m WHERE m.table_name = 'COLA_MARKETS' AND m.column_name = 'SHAPE' AND c.name = 'cola_d'; GMLGEOMETRY -------------------------------------------------------------------------------- <gml:Polygon srsName="SDO:" xmlns:gml="http://www.opengis.net/gml"><gml:outerBou ndaryIs><gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">8,7 8.7653668 6473018,7.15224093497743 9.4142135623731,7.58578643762691 9.84775906502257,8.234 63313526982 10,9 9.84775906502257,9.76536686473018 9.4142135623731,10.4142135623 731 8.76536686473018,10.8477590650226 8,11 7.23463313526982,10.8477590650226 6.5 8578643762691,10.4142135623731 6.15224093497743,9.76536686473018 6,9 6.152240934 97743,8.23463313526982 6.58578643762691,7.5857864376269 7.23463313526982,7.15224 093497743 8,7 </gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Pol ygon>
The following example converts an LRS geometry to a standard geometry and returns the GML fragment for the geometry. (The example uses the definitions and data from Example of LRS Functions.)
SET LONG 40000 -- Convert LRS geometry to standard geometry before using TO_GMLGEOMETRY. SELECT XMLTYPE(SDO_UTIL.TO_GMLGEOMETRY( SDO_LRS.CONVERT_TO_STD_GEOM(route_geometry))) AS GmlGeometry FROM lrs_routes a WHERE a.route_id = 1; GMLGEOMETRY -------------------------------------------------------------------------------- <gml:LineString srsName="SDO:" xmlns:gml="http://www.opengis.net/gml"> <gml:coordinates decimal="." cs="," ts=" ">2,2 2,4 8,4 12,4 12,10 8,10 5,14 </ gml:coordinates> </gml:LineString>
The following examples return GML fragments for a variety of geometry types.
-- Point geometry with coordinates in SDO_ORDINATES. Note the -- coordinates in the GML are (10,10) and the values in the -- SDO_POINT field are discarded. SELECT TO_CHAR( SDO_UTIL.TO_GMLGEOMETRY(sdo_geometry(2001, 8307, sdo_point_type(-80, 70, null), sdo_elem_info_array(1,1,1), sdo_ordinate_array(10, 10))) ) AS GmlGeometry FROM DUAL; GMLGEOMETRY -------------------------------------------------------------------------------- <gml:Point srsName="SDO:8307" xmlns:gml="http://www.opengis.net/gml"><gml:coordi nates decimal="." cs="," ts=" ">10,10 </gml:coordinates></gml:Point> -- Multipolygon SET LONG 40000 SELECT SDO_UTIL.TO_GMLGEOMETRY( sdo_geometry(2007, 8307, null, sdo_elem_info_array(1,1003,1, 13,1003,1, 23,1003,3), sdo_ordinate_array(10.10,10.20, 20.50,20.10, 30.30,30.30, 40.10,40.10, 30.50, 30.20, 10.10, 10.20, 5,5, 5,6, 6,6, 6,5, 5,5, 7,7, 8,8 )) ) AS GmlGeometry FROM DUAL; GMLGEOMETRY -------------------------------------------------------------------------------- <gml:MultiPolygon srsName="SDO:8307" xmlns:gml="http://www.opengis.net/gml"><gml :polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinate s decimal="." cs="," ts=" ">10.1,10.2 20.5,20.1 30.3,30.3 40.1,40.1 30.5,30.2 10 .1,10.2 </gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>< /gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:Lin earRing><gml:coordinates decimal="." cs="," ts=" ">5.0,5.0 5.0,6.0 6.0,6.0 6.0,5 .0 5.0,5.0 </gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygo n></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml: LinearRing><gml:coordinates decimal="." cs="," ts=" ">7.0,7.0 8.0,7.0 8.0,8.0 7. 0,8.0 7.0,7.0 </gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Pol ygon></gml:polygonMember></gml:MultiPolygon> SQL> SET LONG 80 -- Rectangle (geodetic) SELECT TO_CHAR( SDO_UTIL.TO_GMLGEOMETRY(sdo_geometry(2003, 8307, null, sdo_elem_info_array(1,1003,3), sdo_ordinate_array(10.10,10.10, 20.10,20.10 ))) ) AS GmlGeometry FROM DUAL; GMLGEOMETRY -------------------------------------------------------------------------------- <gml:Box srsName="SDO:8307" xmlns:gml="http://www.opengis.net/gml"><gml:coordina tes decimal="." cs="," ts=" ">10.1,10.1 20.1,20.1 </gml:coordinates></gml:Box> -- Polygon with holes SELECT TO_CHAR( SDO_UTIL.TO_GMLGEOMETRY(sdo_geometry(2003, 262152, null, sdo_elem_info_array(1,1003,3, 5, 2003, 1, 13, 2003, 1), sdo_ordinate_array(10.10,10.20, 40.50, 41.10, 30.30, 30.30, 30.30, 40.10, 40.10, 40.10, 30.30, 30.30, 5, 5, 5, 6, 6, 6, 6, 5, 5, 5 ))) ) AS GmlGeometry FROM DUAL; GMLGEOMETRY -------------------------------------------------------------------------------- <gml:Polygon srsName="SDO:262152" xmlns:gml="http://www.opengis.net/gml"><gml:ou terBoundaryIs><gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">10.1,10 .2, 40.5,10.2, 40.5,41.1, 10.1,41.1, 10.1,10.2 </gml:coordinates></gml:LinearRin g></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates de cimal="." cs="," ts=" ">30.3,30.3 30.3,40.1 40.1,40.1 30.3,30.3 </gml:coordinate s></gml:LinearRing></gml:innerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><g ml:coordinates decimal="." cs="," ts=" ">5,5 5,6 6,6 6,5 5,5 </gml:coordinates>< /gml:LinearRing></gml:innerBoundaryIs></gml:Polygon> -- Creating an XMLTYPE from the GML fragment. Also useful for "pretty -- printing" the GML output. SET LONG 40000 SELECT XMLTYPE( SDO_UTIL.TO_GMLGEOMETRY(sdo_geometry(2003, 262152, null, sdo_elem_info_array(1,1003,1, 11, 2003, 1, 21, 2003, 1), sdo_ordinate_array(10.10,10.20, 40.50,10.2, 40.5,41.10, 10.1,41.1, 10.10, 10.20, 30.30,30.30, 30.30, 40.10, 40.10, 40.10, 40.10, 30.30, 30.30, 30.30, 5, 5, 5, 6, 6, 6, 6, 5, 5, 5 ))) ) AS GmlGeometry FROM DUAL; GMLGEOMETRY -------------------------------------------------------------------------------- <gml:Polygon srsName="SDO:262152" xmlns:gml="http://www.opengis.net/gml"><gml:ou terBoundaryIs><gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">10.1,10 .2 40.5,10.2 40.5,41.1 10.1,41.1 10.1,10.2 </gml:coordinates></gml:LinearRing></ gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates decima l="." cs="," ts=" ">30.3,30.3 30.3,40.1 40.1,40.1 40.1,30.3 30.3,30.3 </gml:coor dinates></gml:LinearRing></gml:innerBoundaryIs><gml:innerBoundaryIs><gml:LinearR ing><gml:coordinates decimal="." cs="," ts=" ">5,5 5,6 6,6 6,5 5,5 </gml:coordin ates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon>
The following example uses the TO_GMLGEOMETRY function with the Oracle XML DB XMLTYPE data type and the XMLELEMENT and XMLFOREST functions.
SELECT xmlelement("State", xmlattributes( 'http://www.opengis.net/gml' as "xmlns:gml"), xmlforest(state as "Name", totpop as "Population", xmltype(sdo_util.to_gmlgeometry(geom)) as "gml:geometryProperty")) AS theXMLElements FROM states WHERE state_abrv in ('DE', 'UT'); THEXMLELEMENTS -------------------------------------------------------------------------------- <State xmlns:gml="http://www.opengis.net/gml"> <Name>Delaware</Name> <Population>666168</Population> <gml:geometryProperty> <gml:Polygon srsName="SDO:" xmlns:gml="http://www.opengis.net/gml"> <gml:outerBoundaryIs> <gml:LinearRing> <gml:coordinates decimal="." cs="," ts=" ">-75.788704,39.721699 -75.78 8704,39.6479 -75.767014,39.377106 -75.76033,39.296497 -75.756294,39.24585 -75.74 8016,39.143196 -75.722961,38.829895 -75.707695,38.635166 -75.701912,38.560619 -7 5.693871,38.460011 -75.500336,38.454002 -75.341614,38.451855 -75.049339,38.45165 3 -75.053841,38.538429 -75.06015,38.605465 -75.063263,38.611275 -75.065308,38.62 949 -75.065887,38.660919 -75.078697,38.732403 -75.082527,38.772045 -75.091667,38 .801208 -75.094185,38.803699 -75.097572,38.802986 -75.094116,38.793579 -75.09926 6,38.78756 -75.123619,38.781784 -75.137962,38.782703 -75.18692,38.803772 -75.215 019,38.831547 -75.23735,38.849014 -75.260498,38.875 -75.305908,38.914673 -75.316 399,38.930309 -75.317284,38.93676 -75.312851,38.945576 -75.312859,38.945618 -75. 31205,38.967804 -75.31778,38.986012 -75.341431,39.021233 -75.369606,39.041359 -7 5.389229,39.051422 -75.40181,39.06702 -75.401306,39.097713 -75.411369,39.148029 -75.407845,39.175201 -75.396271,39.187778 -75.39225,39.203377 -75.40181,39.23104 9 -75.402817,39.253189 -75.409355,39.264759 -75.434006,39.290424 -75.439041,39.3 13065 -75.453125,39.317093 -75.457657,39.326653 -75.469231,39.330677 -75.486336, 39.341743 -75.494888,39.354324 -75.504448,39.357346 -75.51284,39.366291 -75.5129 24,39.366482 -75.523773,39.392052 -75.538651,39.415707 -75.56749,39.436436 -75.5 9137,39.463696 -75.592941,39.471806 -75.590019,39.488026 -75.587311,39.496136 -7 5.5774,39.508076 -75.554192,39.506947 -75.528442,39.498005 -75.530373,39.510303 -75.527145,39.531326 -75.52803,39.535168 -75.53437,39.540592 -75.519386,39.55528 6 -75.512291,39.567505 -75.515587,39.580639 -75.528046,39.584 -75.538269,39.5935 67 -75.554016,39.601727 -75.560143,39.622578 -75.556602,39.6348 -75.549599,39.63 7699 -75.542397,39.645901 -75.535507,39.647099 -75.514999,39.668499 -75.507523,3 9.69685 -75.496597,39.701302 -75.488914,39.714722 -75.477997,39.714901 -75.47550 2,39.733501 -75.467972,39.746975 -75.463707,39.761101 -75.448494,39.773857 -75.4 38301,39.783298 -75.405701,39.796101 -75.415405,39.801678 -75.454102,39.820202 - 75.499199,39.833199 -75.539703,39.8381 -75.5802,39.838417 -75.594017,39.837345 - 75.596107,39.837044 -75.639488,39.82893 -75.680145,39.813839 -75.71096,39.796352 -75.739716,39.772881 -75.760689,39.74712 -75.774101,39.721699 -75.788704,39.721 699 </gml:coordinates> </gml:LinearRing> </gml:outerBoundaryIs> </gml:Polygon> </gml:geometryProperty> </State> <State xmlns:gml="http://www.opengis.net/gml"> <Name>Utah</Name> <Population>1722850</Population> <gml:geometryProperty> <gml:Polygon srsName="SDO:" xmlns:gml="http://www.opengis.net/gml"> <gml:outerBoundaryIs> <gml:LinearRing> <gml:coordinates decimal="." cs="," ts=" ">-114.040871,41.993805 -114. 038803,41.884899 -114.041306,41 -114.04586,40.116997 -114.046295,39.906101 -114. 046898,39.542801 -114.049026,38.67741 -114.049339,38.572968 -114.049095,38.14864 -114.0476,37.80946 -114.05098,37.746284 -114.051666,37.604805 -114.052025,37.10 3989 -114.049797,37.000423 -113.484375,37 -112.898598,37.000401 -112.539604,37.0 00683 -112,37.000977 -111.412048,37.001514 -111.133018,37.00079 -110.75,37.00320 1 -110.5,37.004265 -110.469505,36.998001 -110,36.997967 -109.044571,36.999088 -1 09.045143,37.375 -109.042824,37.484692 -109.040848,37.881176 -109.041405,38.1530 27 -109.041107,38.1647 -109.059402,38.275501 -109.059296,38.5 -109.058868,38.719 906 -109.051765,39 -109.050095,39.366699 -109.050697,39.4977 -109.050499,39.6605 -109.050156,40.222694 -109.047577,40.653641 -109.0494,41.000702 -109.2313,41.00 2102 -109.534233,40.998184 -110,40.997398 -110.047768,40.997696 -110.5,40.994801 -111.045982,40.998013 -111.045815,41.251774 -111.045097,41.579899 -111.045944,4 2.001633 -111.506493,41.999588 -112.108742,41.997677 -112.16317,41.996784 -112.1 72562,41.996643 -112.192184,42.001244 -113,41.998314 -113.875,41.988091 -114.040 871,41.993805 </gml:coordinates> </gml:LinearRing> </gml:outerBoundaryIs> </gml:Polygon> </gml:geometryProperty> </State>
Related Topics
Parent topic: SDO_UTIL Package (Utility)