16.20 - FNC_GeomSetWKB - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
April 2020
Content Type
Programming Reference
Publication ID
B035-1147-162K
Language
English (United States)

Purpose

Set the value of a Geometry type using a Well-Known Binary (WKB) representation of the Geometry.

Syntax

void
FNC_GeomGetWKB(GEO_HANDLE      geoHandle,
               byte*           wkb,
               FNC_GeomSize_t  wkbSize,
               int             srid)
GEO_HANDLE geoHandle
A handle to a Geometry type that is defined to be a return value for a UDF/UDM or an INOUT/OUT parameter to an external stored procedure.
byte* wkb
A pointer to the WKB value to be set.
FNC_GeomSize_t wkbSize
Size in bytes of the WKB value.
int srid
Spatial Reference System Identifier of the Geometry to be set.

Usage Notes

FNC_GeomSetWKB sets the value of a Geometry using a WKB byte string. The wkb parameter containing the WKB string, the wkbSize and the SRID to be set for the Geometry are passed as input.

FNC_GeomSetWKB should be called only for inline ST_Geometry values. If used with a LOB-based ST_Geometry value, a 7579 error is generated: FNC_GeomSetWKB is only valid for inline ST_Geometry values.

Example: Using FNC_GeomGetWKB and FNC_GeomSetWKB to get and set a geometry WKB

The following UDF takes a ST_Geometry parameter as input, retrieves the WKB representation, and sets the return ST_Geometry value with it. It assumes the Geometry size is small enough to be read using a single read.

CREATE FUNCTION geomUDF3(P1 st_geometry)
RETURNS ST_GEOMETRY
NO SQL
PARAMETER STYLE SQL
DETERMINISTIC
LANGUAGE C
EXTERNAL NAME 'CS!geomUDF3!geomUDF3.c';

void geomUDF3(GEO_HANDLE* geom_handle,
              GEO_HANDLE* return_handle,
              int* indicator_thisGeom,
              int* indicator_returnValue,
              char    sqlstate[6],
              SQL_TEXT              extname[129],
              SQL_TEXT              specific_name[129],
              SQL_TEXT              error_message[257] )
{
     FNC_GeomSize_t geomsize;
     FNC_GeomSize_t bytesRead;
     FNC_GeomSize_t offset;
     FNC_GeomSize_t size;
     FNC_GeomSize_t wkbSize;
     byte* wkbBuffer;
     FNC_GeomSize_t wkbBufferSize;
     int srid;

    /* Get the Geometry WKT Size */
      geomsize = FNC_GeomGetWKBSize(*geom_handle); 

    /* Read the WKB value */
     wkbBuffer = (byte*)FNC_Malloc(geomsize);
     wkbBufferSize = geomsize;
     size = geomsize;
     offset = 0;    
     /* Get the WKB value */
      FNC_GeomGetWKB(*geom_handle,wkbBuffer, wkbBufferSize, 
 &wkbSize, &srid); 
                                                                                                                           
     /* Set the return value */
      FNC_GeomSetWKB(*return_handle, wkbBuffer, wkbSize,0); 
    *indicator_returnValue = 0;
     FNC_free(wkbBuffer);
}