Example: Using the com.teradata.fnc.ST_Geometry Class For an IN and OUT ST_Geometry Parameter - 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ā„¢

This example returns a geometry that is the duplicate of the input geometry.

REPLACE PROCEDURE dupGeometry(IN geom_in ST_Geometry,
                              OUT geom_out ST_Geometry)
      LANGUAGE JAVA
      NO SQL
      PARAMETER STYLE JAVA 
      EXTERNAL NAME 
     	'UDF_JAR:UserDefinedFunctions.dupGeometry(com.teradata.fnc.ST_Geometry, com.teradata.fnc.ST_Geometry)';

public static void dupGeometry(com.teradata.fnc.ST_Geometry geom_in, com.teradata.fnc.ST_Geometry[] geom_out) throws SQLException
{
  java.io.InputStream inWKT;
  java.io.OutputStream outWKT;
  byte [] wkt;
  int srid;
  int numbytes;

  // Get the WKT InputStream and SRID of the input geometry.
  inWKT = geom_in.getWKT();
  srid = geom_in.getSRID();

  // Read the input WKT into a byte array.
  numbytes = inWKT.read(wkt);

  // Retrieve an OutputStream where we can write the WKT to the return geoemtry.
  If(geom_out == null | geom_out.lengh == 0)
       throw new SQLException();
  outWKT = geom_out[0].setWKT();

  // Write the input WKT to the return geometry
  outWKT.write(wkt);

  // Set the SRID of the return ST_Geometry to the same value as the input geometry
  geom_out[0].setSRID(srid);
}