Search code examples
oracle-databasegisspatialoracle-spatial

ST_Boundary for Oracle Spatial


Is it possible to do the equivalent of ST_Boundary with Oracle Spatial? As in get a LINESTRING/MULTILINESTRING from a POLYGON, or a MULTIPOINT from a LINESTRING?

I know the other vendors support it:

https://postgis.net/docs/ST_Boundary.html

https://learn.microsoft.com/en-us/sql/t-sql/spatial-geometry/stboundary-geometry-data-type?view=sql-server-ver16


Solution

  • To get boundary, please see SDO_UTIL.POLYGONTOLINE

    There is not a built in fn for linestring to multipoint. But here is a simple fn to do it (assuming 2D):

    CREATE OR REPLACE FUNCTION multipoint_from_line (line_geom SDO_GEOMETRY)
       RETURN SDO_GEOMETRY DETERMINISTIC PARALLEL_ENABLE IS
    
       multipoint SDO_GEOMETRY := NULL;
    BEGIN
       IF line_geom IS NOT NULL
       THEN
         multipoint := line_geom;
    
         IF multipoint.sdo_ordinates.count = 0
         THEN
           multipoint := NULL;
         ELSE
           multipoint.sdo_gtype := 2005;
           multipoint.sdo_elem_info := 
    sdo_elem_info_array(1,1,multipoint.sdo_ordinates.count/2);
         END IF;
       END IF;
    
       return multipoint;
    END;
    /
    
    -- Calling from SQL
    SELECT multipoint_from_line 
    (sdo_geometry(2002,4326,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(0,0,1,1,3,3)))
    FROM dual;
    
    -- Calling from PL/SQL
    DECLARE
       multipoint SDO_GEOMETRY;
    BEGIN
       multipoint := multipoint_from_line 
    (sdo_geometry(2002,4326,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(0,0,1,1,3,3)));
    END;
    /