< Prev - Examples - Next >

Special Oracle Type SDO_GEOMETRY

Example Description

Important Notes !

PL/SQL Function

The function 'GET_SDO_GEOMETRY' demonstrates the use of SDO_GEOMETRY'.
PL/SQL Function : GET_SDO_GEOMETRY
create or replace function get_sdo_geometry return sdo_geometry
/**
 * Spartial demo.
 *
 * @return Spartial type SDO_GEOMETRY.
 */
is
begin
  return SDO_GEOMETRY(
    2003,  -- two-dimensional polygon
    NULL,
    NULL,
    SDO_ELEM_INFO_ARRAY(1,1003,3),  -- one rectangle (1003 = exterior)
    SDO_ORDINATE_ARRAY(1,1, 5,7)    -- only 2 points needed to
                                    -- define rectangle (lower left and upper right) with
                                    -- Cartesian-coordinate data
  ); 
end get_sdo_geometry;

Factory API : Calling the PL/SQL function

Using the static factory to get the remote service.
Java Calling Class : SdoGeometry.java
package plsql_workbench_examples.factoryapi;

import factory.ExamplesRPCFactory;
import oracle.spatial.geometry.JGeometry;
import service.GetSdoGeometryService;

public class SdoGeometry {
  public static void main(String[] args) {
    try {
      // get service
      GetSdoGeometryService service = ExamplesRPCFactory.getGetSdoGeometryService();

      // stored procedure produces data of a rectangle
      JGeometry rectangle = service.call();

      System.out.format("lower left corner : x=%f    y=%f%n",
                        rectangle.getFirstPoint()[0],
                        rectangle.getFirstPoint()[1]);
      System.out.format("upper right corner : x=%f    y=%f%n",
                        rectangle.getLastPoint()[0],
                        rectangle.getLastPoint()[1]);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

< Prev - Examples - Next >