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

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

Purpose

Set the value of a Geometry type using a Well-Known Binary (WKB) BLOB represented by a LOB_RESULT_LOCATOR.

Syntax

void
FNC_GeomGetWKBBlob(GEO_HANDLE          geoHandle,
                   LOB_RESULT_LOCATOR  geoBlob,
                   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.
LOB_RESULT_LOCATOR geoBlob
LOB locator for the WKB BLOB containing the return value for the ST_Geometry type.
int srid
Spatial Reference System Identifier of the Geometry to be set.

Usage Notes

FNC_GeomSetWKBBlob sets the ST_Geometry return/OUT/INOUT parameter value using a LOB result locator. The ST_Geometry Handle geoHandle is passed as input along with a LOB result locator geoBlob. The geoBlob locator value is obtained by calling FNC_GeomGetResultWKBBlob, and LOB FNC routines are used to append the WKB to the BLOB. It is then passed to FNC_GeomSetWKBBlob.

The Blob returned by this routine must contain well-formed WKB data else the FNC routine will return an error ERRAMPFNCUDTBADARG.

FNC_GeomSetWKBBlob should be used only with a LOB-based ST_Geometry value. Otherwise a 7579 error is generated: FNC_GeomSetWKBBlob is only valid for LOB-based ST_Geometry values. Use FNC_GeomSetWKB() instead.

Example: Using FNC_GeomGetResultWKBBlob and FNC_GeomSetWKBBlob to retrieve and set the value of a return ST_Geometry

The following function takes a ST_Geometry parameter and returns an ST_Geometry that has the same value. It first retrieves the Well-Known Binary format from the input geometry. It then retrieves the LOB result locator from the return ST_Geometry, appends the WKB to it, and then sets the value of the return ST_Geometry.

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

void geo_wkb( GEO_HANDLE  *geo_in,
              GEO_HANDLE  *geo_out,
              int         *indicator_geo_in,
              int         *indicator_geo_out,
              char        sqlstate[6],
              SQL_TEXT    extname[129],
              SQL_TEXT    specific_name[129],
              SQL_TEXT    error_message[257])
{
    LOB_RESULT_LOCATOR geoBlob_out;
    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, max_length2, numLobs, numLobs2;

    /* If input is null set return value to null. */
    if (*indicator_geo_in == -1 )
    {
        *indicator_geo_out = -1;
        return;
    }


    /* Get the Input Geometry Info */
     FNC_GetGeometryInfo(*geo_in,&max_length, &numLobs);

    /* Get the Output Geometry Info */
     FNC_GetGeometryInfo(*geo_out,&max_length2, &numLobs2);

    /* 
     * Copy geo_in ST_Geometry value to geo_out ST_Geometry value.
     *
     */
    if(numLobs ==1 && numLobs2 ==1)
    {
      /* Get the LOB_RESULT_LOCATOR of geo_out. */
       FNC_GeomGetResultWKBBlob(*geo_out, &geoBlob_out); 

      /* 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(geoBlob_out, buffer, actlen, &actlen);
      FNC_LobClose(id);

      /* Set the return ST_Geometry value */
       FNC_GeomSetWKBBlob(*geo_out, geoBlob_out, srid); 
    }
}