The ST_GeomFromWKB() function
The ST_GeomFromWKB() function takes a well-known binary representation and a spatial reference ID to return a geometry object.
The ST_GeomFromWKB() function does not support the ST_GeomCollection.
Syntax
ST_GeomFromWKB(WKB lvarchar, SRID integer)
Return type
ST_Geometry
Example
The following C code fragment contains ODBC functions included with the HCL® OneDB® spatial data type functions that insert data into the lots table.
The
lots table was created with two columns: the lot_id, which
uniquely identifies each lot, and the lot polygon column, which
contains the geometry of each lot:
CREATE TABLE lots (lot_id integer,
lot ST_MultiPolygon);
The ST_GeomFromWKB() function
converts WKB representations into HCL
OneDB spatial
geometry. The entire INSERT statement is copied into a wkb_sql CHAR
string. The INSERT statement contains parameter markers to accept
the lot_id and lot data, dynamically:
/* Create the SQL insert statement to populate the lots
* table. The question marks are parameter markers that indicate
* the column values that will be inserted at run time. */
sprintf(sql_stmt,
"INSERT INTO lots (lot_id, lot) "
"VALUES(?, ST_GeomFromWKB(?, %d))", srid);
/* Prepare the SQL statement for execution. */
rc = SQLPrepare (hstmt, (unsigned char *)sql_stmt, SQL_NTS);
/* Bind the lot_id to the first parameter. */
pcbvalue1 = 0;
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG,
SQL_INTEGER, 0, 0,
&lot_id, 0, &pcbvalue1);
/* Bind the lot geometry to the second parameter. */
pcbvalue2 = lot_wkb_len;
rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_BINARY,
SQL_INFX_UDT_LVARCHAR, lot_wkb_len, 0,
lot_wkb_buf, lot_wkb_len, &pcbvalue2);
/* Execute the insert statement. */
rc = SQLExecute (hstmt);