GeoJSON Without Conversion In Oracle Spatial 23c



In Oracle 23c you can store and query GeoJSON directly without conversion between JSON/GeoJSON and SDO_GEOMETRY.

Oracle 23c also ensures better compatibility with GIS applications like PostGIS, ArcGIS, QGIS and web-based mapping tools.

In the previous version,you should manually convert GeoJSON to SDO_GEOMETRY for inserting, and when you had a query required extracting SDO_GEOMETRY and manually converting it back to GeoJSON.

For example in Oracle 19c :

๐Ÿ“™For Insert GeoJSON Data, you should First Convert it to SDO_GEOMETRY 

INSERT INTO My_Geospatial_Table (id, geom)

VALUES (1,SDO_GEOMETRY(2001, 4326,

SDO_POINT_TYPE(-122.4194, 37.7749, NULL),

NULL, NULL));

๐Ÿ“˜ And when you Query Data you should Convert it Back to GeoJSON  

SELECT

'{"type": "Point", "coordinates": [' ||

geom.sdo_point.x || ',' || geom.sdo_point.y || ']}' AS geojson

FROM My_Geospatial_Table ;


In Oracle 23c :

CREATE TABLE My_Geospatial_Table (

  id NUMBER PRIMARY KEY,

  geojson_data JSON

);

๐Ÿ“™For Insert GeoJSON Data, you do not need to Convert it to SDO_GEOMETRY 

INSERT INTO My_Geospatial_Table (id, geojson_data)

VALUES (

  1, '{"type": "Point", "coordinates": [-122.4194, 37.7749]}'

); 

๐Ÿ“˜ And you Query Without Conversion

SELECT geojson_data FROM My_Geospatial_Table  WHERE id = 1;


FEUTURE

19c or Earlier

23c

Store GeoJSON Directly?

๐Ÿ˜ƒ

Query Without Conversion?

๐Ÿ˜ƒ

Use JSON Functions for Spatial Queries?

๐Ÿ˜ƒ

Native Indexing on GeoJSON?

๐Ÿ˜ƒ


๐Ÿ“Œ Indexing  on GeoJSON fields

Oracle 23c fully supports spatial indexing on JSON and GeoJSON fields. 

* This makes spatial queries much faster *

CREATE SEARCH INDEX geojson_spatial_idx ON geojson_table(geojson_data) FOR JSON SPATIAL;

๐Ÿ“Œ SQL/JSON Functions to Extract Coordinates

SELECT JSON_VALUE(geojson_data, '$.coordinates[0]') AS longitude, JSON_VALUE(geojson_data, '$.coordinates[1]') AS latitude FROM geojson_table;

๐Ÿ“Œ SQL/JSON Functions to Find Points Within a Certain Distance

SELECT id, geojson_data FROM geojson_table WHERE SDO_WITHIN_DISTANCE( JSON_VALUE(geojson_data, '$.coordinates'), 'POINT(-121 36)', 'distance=500 unit=km' ) = 'TRUE';

by this code you can find all points within 500 km of (-121, 36)

๐Ÿ“Œ SQL/JSON Functions to Find the Nearest Point to a Given Location

 SELECT id, geojson_data
FROM geojson_table ORDER BY SDO_NN( JSON_VALUE(geojson_data, '$.coordinates'), 'POINT(-121 36)' ) FETCH FIRST 1 ROW ONLY;



Comments

Popular posts from this blog

Installation of Oracle Database 23ai and APEX 24.2 and ORDS 24.4 on Windows Step-by-Step

Building a Fully Local AI-Powered Assistant with Oracle APEX and Vector Search #APEXCONN2025 #orclAPEX

Configuration of ORDS: Standalone, Tomcat, and WebLogic on Windows Step-by-Step

✔ RTL Map Region Labels APEX 24.2 & ๐ŸŒGeoCoding

Building an AI-Powered Resume Matching System Using Oracle APEX and 23ai Vector Search๐Ÿ˜Ž

JavaScript In Oracle APEX (Client Side)

Vector Tiles in Oracle Spatial 23

Leveraging ONNX Models for AI Vector Search in Oracle Cloud Database 23ai

My Experience at Oracle CloudWorld Tour in Frankfurt – April 10, 2025

What is SYS.ODCI (SYS.ODCINumberList or SYS.ODCIVarchar2List) and How Can Use it in APEX ?