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;
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.