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

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);
}