FNC_GeomSetWKB Function | C Library Functions | Teradata Vantage - FNC_GeomSetWKB - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
rin1593638965306.ditamap
dita:ditavalPath
rin1593638965306.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantageā„¢

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)

Syntax Elements

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.
wkb
A pointer to the WKB value to be set.
wkbSize
Size in bytes of the WKB value.
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);
}