FNC_GeomGetWKB Function | C Library Functions | Teradata Vantage - 17.10 - FNC_GeomGetWKB - 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)

Returns the Well-Known Binary (WKB) representation of the Geometry as a binary string.

Syntax

void
FNC_GeomGetWKB(GEO_HANDLE  geoHandle,
               byte *           wkbBuffer,
		             FNC_GeomSize_t   wkbBufferSize,
               FNC_GeomSize_t *wkbSize,
               int            *srid)

Syntax Elements

geoHandle
A handle to an ST_Geometry type that is defined to be an input parameter to an external routine.
wkbBuffer
A pointer to the buffer that holds the WKB value.
wkbBufferSize
Size in bytes of the wkbBuffer passed to the FNC routine.
wkbSize
Size in bytes of the WKB data returned by the routine.
srid
Spatial Reference System Identifier of the Geometry returned by the routine.

Usage Notes

FNC_GeomGetWKB can be used to get the Well-Known Binary representation of the Geometry. The GEO_HANDLE for the Geometry is passed in as input along with a pointer to a buffer (wkbBuffer) and the buffer size (wkbBufferSize). The wkbBuffer size must be large enough to hold the WKB data. To allocate the appropriate buffer size, the FNC_GetGeomeryInfo function or FNC_GetWKBSize function can be used to find the Geometry length.

The routine fills up the wkbBuffer with the WKB representation of the geometry. The wkbSize and srid fields are also filled in by the FNC routine.

This routine should be called only on inline ST_Geometry values. If invoked on a LOB-based ST_Geometry value, a 7579 error is generated: FNC_GeomGetWKB is only valid for inline ST_Geometry values.

Example: Using FNC_GeomGetWKB to retrieve a ST_Geometry WKB

The following example function takes a ST_Geometry parameter and retrieves the Well-Known Binary format for the geometry. It returns the WKB retrieved as a BLOB.

CREATE FUNCTION geomUDF2(P1 st_geometry(1000))
RETURNS BLOB AS LOCATOR
NO SQL
PARAMETER STYLE SQL
DETERMINISTIC
LANGUAGE C
EXTERNAL NAME 'CS!geomUDF2!geomUDF2.c';

void geomUDF2(GEO_HANDLE *geom_handle,
              LOB_RESULT_LOCATOR *return_handle,
              int*        indicator_thisGeom,
              int*        indicator_returnLOB,
              char        sqlstate[6],
              SQL_TEXT    extname[129],
              SQL_TEXT    specific_name[129],
              SQL_TEXT    error_message[257] )
{
     FNC_GeomSize_t geomsize;
     FNC_GeomSize_t wkbSize;
     byte* wkbBuffer;
     FNC_GeomSize_t wkbBufferSize;
     FNC_LobLength_t actlen;
     int srid;

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

    wkbBuffer = (byte*)FNC_Malloc(geomsize);
    wkbBufferSize = geomsize;
    /* Get the WKB value */
     FNC_GeomGetWKB(*geom_handle,wkbBuffer, wkbBufferSize, 
         &wkbSize, &srid); 
                                                                                                                           
    /* Append the WKB to a LOB */
     FNC_LobAppend(*return_handle, wkbBuffer, wkbBufferSize, 
         &actlen); 
    *indicator_returnLob = 0;
    FNC_free(wkbBuffer);
}