OceanBase Database in Oracle-compatible mode provides functions for constructing, querying, calculating, and formatting spatial objects.
Function
The following table describes the functions of the SDO_GEOMETRY type.
Name |
Returns |
Description |
|---|---|---|
| GET_DIMS() | NUMBER | Obtains the dimension information of a geometric object. It returns an integer indicating the number of dimensions of the geometric object. The value is defined in SDO_GTYPE. The result is the same as that of the ST_COORDDIM expression. |
| ST_COORDDIM() | NUMBER | Obtains the dimension information of a geometric object. The result is the same as that of GET_DIMS. |
| GET_GTYPE() | NUMBER | Obtains the type code of a geometric object. It returns an integer indicating the type of the geometric object. For example, 2001 indicates a point, 2002 indicates a line, and 2003 indicates a polygon. |
| ST_ISVALID() | NUMBER | Checks the validity of a geometric object. It returns a Boolean value indicating whether the geometric object is valid. TRUE is returned if the geometric object is valid; otherwise, FALSE is returned. |
| GET_WKB() | BLOB | Obtains the Well-Known-Binary (WKB) format of a geometric object. It returns a binary string indicating the WKB format of the geometric object without the SRID. |
| GET_WKT() | CLOB | Obtains the Well-Known-Text (WKT) format of a geometric object. It returns a string indicating the WKT format of the geometric object without the SRID. |
| GET_GEOJSON() | CLOB | Obtains the JSON format of a geometric object. It returns a string indicating the JSON format of the geometric object. The JSON format output of the spatial object is returned. |
The following table describes the functions of the SDO_GEOM package.
Name |
Returns |
Description |
|---|---|---|
| SDO_DISTANCE() | NUMBER | Calculates the distance between two geometric objects. It returns an integer indicating the minimum distance between the two geometric objects. |
| SDO_AREA() | NUMBER | Calculates the planar area of a geometric object. The returned value is in the linear unit of the SRS in which the geometric object is located, without spherical or ellipsoidal conversion. Only 2D planar geometry is supported, and 3D input is not supported. |
The following table describes the spatial relationship judgment functions.
Name |
Returns |
Description |
|---|---|---|
| SDO_CONTAINS() | BOOLEAN | Checks whether one geometric object strictly contains another geometric object (boundary points are not considered as contained). It is equivalent to SDO_RELATE(geomA, geomB, 'mask=CONTAINS'). |
| SDO_ANYINTERACT() | BOOLEAN | Checks whether one geometric object has any form of spatial intersection with another geometric object, such as intersection, contact, or overlap. Contact at the boundary is considered an interaction. It is equivalent to SDO_RELATE(..., 'mask=ANYINTERACT'). |
| SDO_RELATE() | VARCHAR2 | Determines the spatial relationship between two geometric objects. It returns a string (TRUE or FALSE) indicating whether the two objects meet the specified spatial relationship. |
The following table describes the functions of the SDO_UTIL package.
Name |
Returns |
Description |
|---|---|---|
| GETVERTICES() | TABLE | Obtains the vertex coordinates of a geometric object. It supports 2D and 3D geometry. It returns a nested table of the VERTEX_SET_TYPE type, in which each row contains one vertex and includes the X, Y, Z, and W columns and the reserved columns. |
Vertex types (VERTEX_TYPE / VERTEX_SET_TYPE)
SDO_UTIL.GETVERTICES() returns the VERTEX_SET_TYPE type, whose element type is VERTEX_TYPE. Both types are predefined in the SYS schema and do not need to be created manually. When you reference them, you can omit the prefix or use the SYS. prefix. The MDSYS. prefix is not supported.
The fields in VERTEX_TYPE are described as follows:
Field |
Type |
Description |
|---|---|---|
| X, Y | NUMBER | The X and Y coordinates of the vertex. |
| Z | NUMBER | The Z coordinate of the vertex. It is NULL for 2D geometry objects and contains the actual coordinate value for 3D geometry objects. |
| W, V1 to V11 | NUMBER | Reserved fields. They are always NULL in the current version. |
| ID | NUMBER | The vertex ID. It starts from 1 and increases by 1 in vertex order. |
VERTEX_SET_TYPE is a nested table. Note the following when you use it:
- You can declare it as a PL variable or parameter, or construct it in SQL statements and access its fields. It cannot be used as a table column type.
- In SQL statements, expand it with
TABLE(...)before you access its fields. In PL, access the elements by subscript starting from 1, for example,v(1).X;COUNTreturns the number of vertices. - The vertex order matches the order of the coordinate array. For a closed polygon, the first and last vertices are repeated, so a closed quadrilateral returns five vertices.
- If the parameter is
NULL, an empty set is returned (COUNTis 0). You can also construct an empty set withVERTEX_SET_TYPE().
The following example traverses the returned vertices in PL:
SET SERVEROUTPUT ON;
DECLARE
v VERTEX_SET_TYPE;
BEGIN
v := SDO_UTIL.GETVERTICES(
SDO_GEOMETRY(2002, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,2,1),
SDO_ORDINATE_ARRAY(0,0, 1,1, 2,0)));
FOR i IN 1 .. v.COUNT LOOP
DBMS_OUTPUT.PUT_LINE('ID=' || v(i).ID || ' X=' || v(i).X || ' Y=' || v(i).Y);
END LOOP;
END;