If you do not use the Custom Data Type of ODAC, you can also use several built-in SQL functions of Oracle Spatial to perform operations on the SDO_Geometry object.
This method requires that all data be converted at the Database End (whether in select or insert). In some cases, the performance and execution time may be greatly affected.
***. Get_wkb (): *** is the column name of the SDO_Geometry column. This function can convert the SDO_Geometry object to the wkb binary type. When reading and writing data, it can be based on the Blob type (corresponding to byte [] in C #). for example, see the following section ***. get_wkt (): *** is the column name of the SDO_Geometry column. This function can convert the SDO_Geometry object into wkt text. When reading and writing data, it can follow the Clob type (string in C) for example, see the following description. Note: wkt (OGC well-known text) and wkb (OGC well-known binary) are the organization specifications of space data developed by OGC, wkt is described in text format, and wkb is described in binary format. Reference http://blog.sina.com.cn/s/blog_00ccd2400101c2x8.html
Sdo_geometry (wkb, srid) and sdo_geometry (wkt, srid): sdo_geometry constructors. You can pass in a wkb object in blob format or a wkt object in clob format, and a srid, generate the sdo_geometry object in the database. The srid can be selected through select ***. the srid from statement is queried.
Example 1: query by wkb format (in the geoinfo table, there are only two columns, id column is number type, and geo column is SDO_GEOMTRY type)
OracleCommand cmd = new OracleCommand(@"SELECT geo.get_wkb() FROM geoinfo WHERE id= '12' ", con); con.Open(); byte[] wkb = (byte[])cmd.ExecuteScalar();
Example 2: query by wkt format
OracleCommand cmd = new OracleCommand(@"SELECT geo.get_wkt() FROM geoinfo WHERE id= '12' ", con); con.Open(); string wkt = (string)cmd.ExecuteScalar();
Example 3: insert data by wkb
OracleCommand into geom = new OracleCommand (@ "insert into geoinfo values (13, sdo_geometry (: geom, 31297)", con); // 31297 is srid, replace it with your own sridOracleParameter p1 = new OracleParameter (": geom", OracleDbType. blob); p1.Value = wkb; // wkb is byte [] cmdGeom. parameters. add (p1); con. open (); int I = mongogeom. executeNonQuery (); con. close ();
Example 4: insert by wkt
OracleCommand export geom = new OracleCommand (@ "insert into geoinfo values (13, sdo_geometry (: geom, 31297)", con); OracleParameter p1 = new OracleParameter (": geom ", oracleDbType. clob); p1.Value = wkt; // wkt is string1_geom. parameters. add (p1); con. open (); int I = mongogeom. executeNonQuery (); con. close ();