Exposing JTS’s Densifier functionality

I created a densify function within my GEOM package in pure PL/SQL many years ago. Today I decided to expose the Java Topology Suite’s (JTS) Densifier functionality via the Spatial Companion For oracle (SC4O) installer and package.

The Densify PL/SQL wrappers I have created are:

   /**
   * Densify
   * Densifies a geometry using a given distance tolerance,
   * and respecting the input geometry's PrecisionModel
   * @param p_geom      : sdo_geometry : first geometry subject to MBC calculation
   * @param p_precision : int : number of decimal places of precision
   * @param p_distanceTolerance : the distance tolerance to densify
   * @return SDO_GEOMETRY : The densified geometry
   * @author Martin Davis, JTS 1.12
   * @history Simon Greener, September 2011, Original Coding of wrapper
   * @copyright  : Licensed under a Creative Commons Attribution-Share Alike 2.5 Australia License.
   *               http://creativecommons.org/licenses/by-sa/2.5/au/
   **/
   FUNCTION ST_Densify(p_geom              IN mdsys.sdo_geometry,
                       p_precision         IN NUMBER,
                       p_distanceTolerance IN NUMBER)
     RETURN mdsys.sdo_geometry deterministic;
 .
   /**
   * Densify
   * Densifies a geometry using a given distance tolerance,
   * and respecting the input geometry's PrecisionModel
   * Computations occur in projected space described by p_srid parameter.
   * @param p_geom              : sdo_geometry : first geometry subject to MBC calculation
   * @param p_precision         : int          : number of decimal places of precision
   * @param p_distanceTolerance : double       : the distance tolerance to densify
   * @param p_srid              : int          : SRID of projected space in which actual overlay occurs before
   *                                             being projected back to p_geom1.sdo_srid.
   * @return SDO_GEOMETRY : The densified geometry
   * @author Martin Davis, JTS 1.12
   * @history Simon Greener, September 2011, Original Coding of wrapper
   * @copyright  : Licensed under a Creative Commons Attribution-Share Alike 2.5 Australia License.
   *               http://creativecommons.org/licenses/by-sa/2.5/au/
   **/
   FUNCTION ST_Densify(p_geom              IN mdsys.sdo_geometry,
                       p_precision         IN NUMBER,
                       p_distanceTolerance IN NUMBER,
                       p_srid              IN NUMBER)
     RETURN mdsys.sdo_geometry deterministic;

Here is an example using a 3 point line.

 SELECT SC4O.ST_Densify(sdo_geometry('LINESTRING(0 0, 10 10, 10 0, 20 10)',0),2,3) AS dGeom
   FROM dual;
 -- Results
 DGEOM
 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 MDSYS.SDO_GEOMETRY(2002,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),MDSYS.SDO_ORDINATE_ARRAY(0,0,2,2,4,4,6,6,8,8,10,10,10,7.5,10,5,10,2.5,10,0,12,2,14,4,16,6,18,8,20,10))

Which looks like …

Here is an example using an optimized rectangle.

 SELECT SC4O.ST_Densify(sdo_geometry(2003,NULL,NULL,sdo_elem_info_array(1,1003,3),sdo_ordinate_array(1,1,10,10)),2,3) AS dGeom
   FROM dual;
 -- Results
 DGEOM
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 MDSYS.SDO_GEOMETRY(2003,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1),MDSYS.SDO_ORDINATE_ARRAY(1,1,3.25,1,5.5,1,7.75,1,10,1,10,3.25,10,5.5,10,7.75,10,10,7.75,10,5.5,10,3.25,10,1,10,1,7.75,1,5.5,1,3.25,1,1))

Which looks like ….

I hope this is of interest to someone.