GeometryFromShape utilise une forme et un identificateur de système de références spatiales en entrée, et renvoie un objet de type géométrie.
Syntaxe
db2gse.GeometryFromShape(ShapeGeometry Blob(1M), SRID db2gse.coordref)
Type de retour
db2gse.ST_Geometry
Exemples
Le fragment de code C présenté ci-dessous contient des fonctions ODBC imbriquées dans des fonctions SQL Extension Spatiale qui insèrent des données dans la table LOTS.
La table LOTS a été créée avec deux colonnes : la colonne LOT_ID qui identifie chaque parcelle de façon univoque et la colonne des polygones LOT, qui contient la géométrie de chaque parcelle.
CREATE TABLE LOTS ( lot_id integer, lot db2gse.ST_Polygon);
La fonction GeometryFromShape convertit les formes en géométrie Extension Spatiale. La totalité de l'instruction INSERT est copiée dans shp_sql. L'instruction INSERT contient des marqueurs de paramètre permettant d'accepter dynamiquement les données LOT_ID et LOT.
/* Create the SQL insert statement to populate the lot_ id and the lot columns. The question marks are parameter markers that indicate the lot_id and lot values that will be retrieved at runtime. */ strcpy (shp_sql,"insert into LOTS (lot_id, lot) values (?, db2gse.GeometryFromShape (cast(? as blob(1m)), db2gse.coordref()..srid(0)))"); /* Allocate memory for the SQL statement handle and associate the statement handle with the connection handle. */ rc = SQLAllocStmt (handle, &hstmt); /* Prepare the SQL statement for execution. */ rc = SQLPrepare (hstmt, (unsigned char *)shp_sql, SQL_NTS); /* Bind the integer key value 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 shape to the second parameter. */ pcbvalue2 = blob_len; rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_BLOB, blob_len, 0, shape_blob, blob_len, &pcbvalue2); /* Execute the insert statement. */ rc = SQLExecute (hstmt);