Example: Using the com.teradata.fnc.ST_Geometry Class For an IN and OUT ST_Geometry Parameter - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
rin1593638965306.ditamap
dita:ditavalPath
rin1593638965306.ditaval
dita:id
B035-1147
lifecycle
previous
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);
}