The ST_PolyFromWKB() function

The ST_PolyFromWKB() function takes a well-known binary representation of type ST_Polygon and a spatial reference ID to return an ST_Polygon.

Syntax

ST_PolyFromWKB(wkb lvarchar, SRID integer)

Return type

ST_Polygon

Example

The sensitive_areas table contains several columns that describe the threatened institutions in addition to the zone column, which stores the institution ST_Polygon geometries:
CREATE TABLE sensitive_areas (id     integer,
                              name   varchar(128),
                              size   float,
                              type   varchar(10),
                              zone   ST_Polygon);
The program fragment populates the sensitive_areas table:
    /* Create the SQL insert statement to populate the sensitive_areas
     * table. The question marks are parameter markers that indicate
     * the column values that will be inserted at run time. */
    sprintf(sql_stmt,
            "INSERT INTO sensitive_areas (id, name, size, type, zone) "
            "VALUES(?, ?, ?, ?, ST_PolyFromWKB(?, %d))", srid);
    
    /* Prepare the SQL statement for execution. */
    rc = SQLPrepare (hstmt, (unsigned char *)sql_stmt, SQL_NTS);

    /* Bind the id to the first parameter. */
    pcbvalue1 = 0;
    rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG,
                           SQL_INTEGER, 0, 0,
                           &id, 0, &pcbvalue1);

    /* Bind the name to the second parameter. */
    pcbvalue2 = name_len;
    rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR,
                           SQL_CHAR, 0, 0,
                           name, 0, &pcbvalue2);

    /* Bind the size to the third parameter. */
    pcbvalue3 = 0;
    rc = SQLBindParameter (hstmt, 3, SQL_PARAM_INPUT, SQL_C_FLOAT,
                           SQL_REAL, 0, 0,
                           &size, 0, &pcbvalue3);

    /* Bind the type to the fourth parameter. */
    pcbvalue4 = type_len;
    rc = SQLBindParameter (hstmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR,
                           SQL_VARCHAR, type_len, 0,
                           type, type_len, &pcbvalue4);

    /* Bind the zone geometry to the fifth parameter. */
    pcbvalue5 = zone_wkb_len;
    rc = SQLBindParameter (hstmt, 5, SQL_PARAM_INPUT, SQL_C_BINARY,
                           SQL_INFX_UDT_LVARCHAR, zone_wkb_len, 0,
                           zone_wkb_buf, zone_wkb_len, &pcbvalue5);

    /* Execute the insert statement. */
    rc = SQLExecute (hstmt);