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

Teradata Vantageā„¢ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

Set the value of a Geometry type using a Well-Known Text (WKT) string representation of the Geometry in the Latin character set.

Syntax

void
FNC_GeomGetWKT(GEO_HANDLE      geoHandle,
               unsigned char*  wkt,
               FNC_GeomSize_t  wktSize,
               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.
wkt
A pointer to the WKT string in the Latin character set.
wktSize
Size in bytes of the WKT string.
srid
Spatial Reference System Identifier of the Geometry to be set.

Usage Notes

The FNC_GeomSetWKT function sets the value of a Geometry using a WKT string representation. The wkt parameter containing the WKT string, the wktSize, and the SRID to be set for the Geometry are passed as input.

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

Example: Using FNC_GeomGetWKT to retrieve a ST_Geometry WKT

The following example function takes a ST_Geometry parameter and retrieves the Well Known Text format for the geometry. It returns the string back in the ST_Geometry return parameter.

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

void geomUDF1(GEO_HANDLE* geom_handle,
              GEO_HANDLE* return_handle,
              int* indicator_thisGeom,
              int* indicator_returnGeom,
              char  sqlstate[6],
              SQL_TEXT   extname[129],
              SQL_TEXT   specific_name[129],
              SQL_TEXT   error_message[257] )
{
    FNC_GeomSize_t geomsize;
    FNC_GeomSize_t wktSize;
    char* wktBuffer;
    FNC_GeomSize_t wktBufferSize;
    int srid , max_length, numLobs;

    /* Get the Geometry Info */
     FNC_GetGeometryInfo(*geom_handle,&max_length, &numLobs); 
    if(numLobs == 0)
    {
    /* Get the Geometry WKT Size */
     geomsize = FNC_GeomGetWKTSize(*geom_handle); 

     /* Allocate the buffer to hold the WKT. Note that we add 
        1 for the null termination character. */ 
    wktBuffer = (char*)FNC_Malloc(geomsize + 1);
    wktBufferSize = geomsize + 1;

    /* Get the WKT string */
     FNC_GeomGetWKT(*geom_handle,wktBuffer, wktBufferSize, 
                     &wktSize, &srid); 
                                                                                                   
    /* Set the WKT string as return value */
     FNC_GeomSetWKT(*return_handle, wktBuffer, wktSize,0); 
    *indicator_returnGeom = 0;
    FNC_free(wkbBuffer);
    }
}