The Oracle-compatible mode of OceanBase Database provides some functions for the construction, query, calculation, and format conversion of spatial objects.
Function list
The following table describes the member functions of the SDO_GEOMETRY type.
Function |
Return type |
Description |
|---|---|---|
| GET_DIMS() | NUMBER | Obtains the dimension information of a geometry object. It returns an integer that represents the number of dimensions of the geometry object, as defined in the SDO_GTYPE attribute. The value returned is the same as that returned by ST_COORDDIM(). |
| ST_COORDDIM() | NUMBER | Same as GET_DIMS(). |
| GET_GTYPE() | NUMBER | Obtains the type code of a geometry object. It returns an integer that represents the type of the geometry object. For example, 2001 represents a point, 2002 represents a line, and 2003 represents a polygon. |
| ST_ISVALID() | NUMBER | Tests the validity of a geometry object. It returns a Boolean value that indicates whether the geometry object is valid. If the geometry object is valid, TRUE is returned. If not, FALSE is returned. |
| GET_WKB() | BLOB | Obtains the well-known binary (WKB) representation of a geometry object. It returns a binary string that represents the geometry object in the WKB format, without the spatial reference identifier (SRID). |
| GET_WKT() | CLOB | Obtains the well-known text (WKT) representation of a geometry object. It returns a string that represents the geometry object in the WKT format, without the SRID. |
| GET_GEOJSON() | CLOB | Obtains the JSON representation of a geometry object. It returns a string that represents the geometry object in the JSON format. |
The following table describes the functions of the SDO_GEOM package.
Function |
Return type |
Description |
|---|---|---|
| SDO_DISTANCE() | NUMBER | Calculates the distance between two geometry objects. It returns an integer that represents the distance between the geometry objects. |
| SDO_AREA() | NUMBER | Calculates the planar area of a geometry object. The returned value is expressed in the linear units of the SRS of the geometry. Spherical and ellipsoidal conversions are not performed. Only 2D planar geometries are supported. 3D inputs are not supported. |
The following table describes the spatial relationship judgment functions.
Name |
Returns |
Description |
|---|---|---|
| SDO_CONTAINS() | BOOLEAN | Returns TRUE if one geometry object strictly contains another geometry object (boundaries are not considered as containing). This 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 | Returns TRUE or FALSE to indicate whether two geometry objects satisfy the specified spatial relationship. |
The following table describes the functions in the SDO_UTIL package.
Name |
Returns |
Description |
|---|---|---|
| GETVERTICES() | TABLE | Returns the vertex coordinates of a geometry object. Supports 2D and 3D. Returns a nested table of VERTEX_SET_TYPE, each row containing the X, Y, Z, W, and reserved columns of a vertex. |
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;