SDO_UTIL.TO_GEOJSON_JSON
Format
SDO_UTIL.TO_GEOJSON_JSON(
geometry IN SDO_GEOMETRY
) RETURN JSON;
Description
Converts an SDO_GEOMETRY object to a geometry of type JSON in GeoJSON format.
Parameters
geometry
Geometry in SDO_GEOMETRY format to be converted to a JSON object in GeoJSON format.
Usage Notes
For information about using JSON data that is stored in Oracle AI Database, see Oracle AI Database JSON Developer’s Guide.
To convert a geometry in GeoJSON format to an SDO_GEOMETRY object, use the SDO_UTIL.FROM_GEOJSON function.
Examples
The following example shows conversion to and from JSON format. (The example uses the definitions and data from Simple Example: Inserting_ Indexing_ and Querying Spatial Data, specifically the cola_b geometry from the COLA_MARKETS table.)
DECLARE
cola_b_geom SDO_GEOMETRY;
returned_geom SDO_GEOMETRY;
returned_json JSON;
BEGIN
-- Populate geometry variable with cola market cola_b shape.
SELECT c.shape into cola_b_geom FROM cola_markets c
WHERE c.name = 'cola_b';
-- From geometry to JSON
returned_json := SDO_UTIL.TO_GEOJSON_JSON(cola_b_geom);
-- From JSON to geometry
returned_geom := SDO_UTIL.FROM_GEOJSON_JSON(returned_json);
END;
/
The following example shows the GeoJSON object that represents a specified geometry. (In this case the geometry definition reflects the cola_b geometry from the COLA_MARKETS table, defined in Simple Example: Inserting_ Indexing_ and Querying Spatial Data.)
SELECT SDO_UTIL.TO_GEOJSON(SDO_GEOMETRY(2003, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_ARRAY(5, 1, 8, 1, 8, 6, 5, 7, 5, 1))) from DUAL;
SDO_UTIL.TO_GEOJSON(SDO_GEOMETRY(2003,NULL,NULL,SDO_ELEM_INFO_ARRAY(1,1003,1),SD
--------------------------------------------------------------------------------
{ "type": "Polygon", "coordinates": [ [ [5, 1], [8, 1], [8, 6], [5, 7], [5, 1] ]