Method for accessing the sdo_geometry field in Oracle Spatial (in Windows)
Reference URL:
Http://iihero.iteye.com/blog/995152
Blog type: Oracle
Oraclewindowssql. netjdbc
1. With OCI or occi, you can refer to the C ++ implementation in the oraclehome \ MD \ demo \ examples directory after installing oracle,
This method is the most efficient, but the implementation is complicated;
2. Use the oo4o provided by Oracle, Which is com. The code in VB6 is as follows:
'*************************************** ************************
'Gisc lab, Nanjing Normal University
'
'Purpose: This demo shows how to read spatial data from Oracle
'
'Input: User ID = 'Scott ', password = 'tiger', data source = 'apollo ',
'SQL = 'select * From interstates where rownum <2'
'
'Output: xmldocument or xmlreader
'
'Author: Charlie Chen
'
'Data: 7-28-2004
'*************************************** ************************
Dim orasession as orasessionclass
Dim oradatabase as oradatabase
Dim interstates as oradynaset
Dim Geom as oraobject
Dim coords as oracollection
Private sub commandementclick ()
Set orasession = new orasessionclass
Set oradatabase = orasession. opendatabase ("Apollo", "Scott/tiger", 0 &)
Set interstates = oradatabase. createdynaset ("select * From interstates where rownum <2", 0 &)
Set Geom = interstates. Fields ("Geom"). Value
Set coords = Geom. sdo_ordinates
For I = 1 to coords. Size
Debug. Print coords. Item (I)
Next I
End sub
Program readability and maintainability are good. You need to add reference to oip9.tlb.
3. ODP. Net (the data access component provided by Oracle on the. NET platform) can be directly converted into XML coordinate strings in the. NET environment, but the efficiency is too low;
4. JDBC or SDO APIs are ideal in any aspect.
To supplement the implementation on the. NET platform, the Code is as follows:
Private xmldocument getspatialdata (string connectionstring, string SQL)
{
Oracleconnection con = new oracleconnection (connectionstring );
Try
{
Con. open ();
Oraclecommand cmd = new oraclecommand (SQL, con );
Cmd. xmlcommandtype = oraclexmlcommandtype. query;
Cmd. bindbyname = true;
Int rows = cmd. executenonquery ();
Xmlreader = cmd. executexmlreader ();
Xmldocument = new xmldocument ();
Xmldocument. preservewhitespace = true;
Xmldocument. Load (xmlreader );
Return xmldocument;
}
Catch (exception E)
{
Throw E;
}
Finally
{
If (con. State = system. Data. connectionstate. Open) con. Close ();
Con. Dispose ();
}
}
Call:
String constr = "User ID = Scott; Password = tiger; Data Source = Apollo ";
String SQL = "select * From interstates where rownum <2 ";
Xmldocument = getspatialdata (constr, SQL );
Console. writeline (xmldocument! = NULL )? Xmldocument. innerxml: "fail to read ");
--- The --- end;