Method for accessing the sdo_geometry field in Oracle Spatial (in Windows)

Source: Internet
Author: User
Tags oracleconnection

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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.