FNC_GeomGetWKBBlob Function | C Library Functions | Teradata Vantage - FNC_GeomGetWKBBlob - 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 the Well-Known Binary (WKB) representation of the Geometry as a BLOB.

Syntax

void
FNC_GeomGetWKBBlob(GEO_HANDLE  geoHandle,
                   LOB_LOCATOR *geoBlob,
                   int *srid)

Syntax Elements

geoHandle
A handle to an ST_Geometry type that is defined to be an input parameter to an external routine.
geoBlob
LOB locator for the BLOB representation of the ST_Geometry type.
srid
Spatial Reference System Identifier of the Geometry.

Usage Notes

FNC_GeomGetWKBBlob gets a LOB locator for the Well-Known Binary BLOB representation of the ST_Geometry type. The ST_Geometry Handle geoHandle is passed as input. The LOB locator value geoBlob is returned from the function. The user can then use LOB FNC routines to read from the geoBlob locator.

The FNC_GeomGetWKBBlob function can only be used with LOB-based ST_Geometry values. If used with an inline ST_Geometry value, a 7579 error is generated: FNC_GeomGetWKBBlob is only valid for LOB-based ST_Geometry values. Use FNC_GeomGetWKB() instead.

Example: Using FNC_GeomGetWKBBlob to retrieve a ST_Geometry WKB

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

REPLACE FUNCTION getwkb_udf(p1 ST_Geometry)
RETURNS BLOB AS LOCATOR
SPECIFIC getwkb_udf
NO SQL
PARAMETER STYLE SQL
DETERMINISTIC
LANGUAGE C
EXTERNAL NAME 'CS!getwkb_udf!getwkb.c!F!getwkb_udf';

#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>

void getwkb_udf(GEO_HANDLE  *geo_in, 
                LOB_RESULT_LOCATOR *outBlob,
                int         *indicator_geo_in,
                int         *indicator_outBlob,
                char        sqlstate[6],
                SQL_TEXT    extname[129],
                SQL_TEXT    specific_name[129],
                SQL_TEXT    error_message[257])
{
    LOB_LOCATOR geoBlob_in;
    BYTE buffer[64000];
    LOB_CONTEXT_ID id;
    FNC_LobLength_t actlen;
    int trunc_err = 0;
    FNC_LobLength_t blob_length;
    int srid = -1;
    int max_length, numLobs;

    /* If input is null set return value to null. */
    if (*indicator_geo_in == -1 )
    {
        *indicator_outBlob = -1;
        return;
    }
    /* Get the Geometry Info */
     FNC_GetGeometryInfo(*geo_in,&max_length, &numLobs);

    /* 
     * Copy geo_in ST_Geometry value to outClob value.
     *
     */
    if(numLobs == 1)
    {

    /* 
     * Copy geo_in ST_Geometry value to outBlob value.
     *
     */

      /* Get the LOB_LOCATOR and srid of the input ST_Geometry value. */ 
 FNC_GeomGetWKBBlob(*geo_in, &geoBlob_in, &srid); 
 
     FNC_LobOpen(geoBlob_in, &id, 0, 0);
     blob_length = FNC_GetLobLength(geoBlob_in);
     while (FNC_LobRead(id, buffer, blob_length, &actlen) == 0 && !trunc_err)
        trunc_err = FNC_LobAppend(*outBlob, buffer, actlen, &actlen);
     FNC_LobClose(id);
    }
}