FNC_MBRGetValue Function | C Library Functions | Teradata Vantage - FNC_MBRGetValue - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
Product Category
Teradata Vantage™

Returns a buffer containing four double precision values representing the xmin, ymin, xmax, and ymax coordinates that define an MBR (minimum bounding rectangle) type.

Syntax

void
FNC_MBRGetValue(GEO_HANDLE    mbrHandle,
                double *      mbrBuffer,
                int *         mbrSize  )

Syntax Elements

mbrHandle
A handle to an MBR type that is defined to be an input parameter to an external routine.
mbrBuffer
A pointer to a buffer that will hold the four double precision values that define the MBR.
mbrSize
Size in bytes of the value returned in the mbrBuffer buffer.

Usage Notes

FNC_MBRGetValue retrieves the xmin, ymin, xmax, and ymax values of an MBR type. The values are returned in the mbrBuffer as four double precision values. The caller of the function needs to allocate sufficient memory for the mbrBuffer buffer to hold four double precision values.

Example: Using FNC calls to get an MBR type value

The following function takes an MBR type parameter and returns an array of four double precision values representing the xmin, ymin, xmax, and ymax values that define the MBR.

CREATE TYPE MBR_ARRAY AS DOUBLE PRECISION ARRAY[4];
CREATE FUNCTION mbrUDF1(P1 MBR)
RETURNS MBR_ARRAY
NO SQL
PARAMETER STYLE SQL
DETERMINISTIC
LANGUAGE C
EXTERNAL NAME 'CS!mbrUDF1!mbrUDF1.c';

void mbrUDF1 (GEO_HANDLE* mbr_handle,
              ARRAY_HANDLE* resultArray,
              int* indicator_thismbr,
              int* indicator_Result,
              char       sqlstate[6],
              SQL_TEXT   extname[129],
              SQL_TEXT   specific_name[129],
              SQL_TEXT   error_message[257] )
{
     double* mbrBuffer;
     int returnSize;
     int mbrBufferSize;
     array_info_t arrayInfo;
     bounds_t arrayScope[FNC_MAXARRAYDIMENSIONS];
     NullBitVecType    *NullBitVector;

     mbrBufferSize = 4 * SIZEOF_DOUBLE_PRECISION;
     mbrBuffer = (double*)FNC_Malloc(mbrBufferSize);
     /* Get the MBR value */
      FNC_MBRGetValue(*mbr_handle,mbrBuffer,&returnSize); 

      /* get element type information for the ARRAY */
      FNC_GetArrayTypeInfo(*((ARRAY_HANDLE*)resultArray),
                           &arrayInfo,
                           arrayScope);     
     /* Allocate a new NullBitVector */
      NullBitVector = (NullBitVecType*)FNC_malloc(1);

      /* Set array elements within the range. */
      FNC_SetArrayElementsWithMultiValues(
                      *((ARRAY_HANDLE*)resultArray),
                       arrayScope,
                      (void*)mbrBuffer,
                       mbrBufferSize, NullBitVector,1);

    *indicator_Result = 0;
     FNC_free(NullBitVector);
     FNC_free(mbrBuffer);
}