Invoking Oracle Spatial from a Custom Command

Consider a requirement where the centroid of a set of points needs to be retrieved within a custom command. This can be achieved using the ‘GTDataProvider.DataContext.Execute‘-method:

IGTApplication GTApp = GTClassFactory.Create<IGTApplication>( );

string coors = "0, 0, 0, 10, 0, 0, 10, 10, 0, 0, 10, 0, 0, 0, 0"; // change to actual coordinates
string sql = $@"WITH shape AS
  ( 
  	select 1 id, sdo_geometry( 3003, NULL, NULL
         , sdo_elem_info_array( 1, 1003, 1)
         , sdo_ordinate_array({coors} )) G FROM dual
  )
SELECT s.ID, t.x, t.y FROM shape S, sdo_util.getvertices( sdo_geom.sdo_centroid( S.G)) t";

ADODB.Recordset rs = GTApp.DataContext.Execute( sql, out _, (int)ADODB.CommandTypeEnum.adCmdText);

if( rs == null) return;
if( rs.RecordCount == 0 ) return;
rs.MoveFirst( );

string x = System.Convert.ToString( rs.Fields[ "X"].Value);
string y = System.Convert.ToString( rs.Fields[ "Y"].Value);

System.Diagnostics.Debug.WriteLine( string.Format( "x={0}, y={1}", x, y)); // x=5, y=5

rs.Close();
rs = null;

Related Posts

Shortening CustomCommand development time by using a proxy

One of the most time-consuming processes when developing with Hexagon G/Technology is creating custom commands. The usual development approach consists of the following iterative process: During testing,…

Rubberbanding in G/Technology

Whenever a user is digitizing a polygon, he expects feedback when moving the cursor before actually adding a point, the system should ‘rubberband’ the position under the…

sample_set7

Sorting and merging geometries in Oracle Spatial

Consider a requirement where an unsorted set of geometries needs to be merged into a single geometry. Take for instance the following set of geometries where: a…

SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT 3D bug workaround

The SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT function fails for 3D Compound line strings geometries as discussed over here. This is illustrated by the following sample: 2d: produces: While the same geometry…

Invalid Fiber Couplers

Fiber Couplers are used to connect Fiber Inner Ducts in a Fiber Branch Enclosure. You can connect Fiber Inner Ducts using the Fiber Feature Editor by selecting…

Fiber Cables

AdHoc Queries

Introduction G/Technology provides functionality to run dynamic queries, the so called ‘Ad-Hoc queries’. A Large telecom provider in the Netherlands is moving Fiber Cables from CRAMER to…

This Post Has One Comment

  1. Thanks for sharing this tip!

    Btw. didn’t know, that function

    SDO_GEOM.SDO_CENTROID(
    geom1 IN SDO_GEOMETRY,
    tol IN NUMBER
    ) RETURN SDO_GEOMETRY;

    now (ORACLE 19) has a default value for tolerance.

Leave a Reply

Your email address will not be published. Required fields are marked *