Occi uploads Spatial Data

Source: Internet
Author: User

As we all know, data is the blood of GIS. The most important thing about a GIS system is data, and the cost of the whole system construction process is relatively large. To this end, many GIs manufacturers and database manufacturers have gradually launched storage solutions for spatial data.

Among them, Oracle Spatial is a new generation of spatial database launched by Oracle, the largest database vendor at present. It uses the object relational data storage mode to store spatial data.

Spatial data is stored in Oracle Based on the sdo_geometry data type. It is defined:

 

SQL> DESC sdo_geometry

Is the name empty? Type

--------------------------------------------------------------------------

 

Sdo_gtype number

Sdo_srid number

Sdo_point MDSYS. sdo_point_type

Sdo_elem_info MDSYS. sdo_elem_info_array

Sdo_ordinates MDSYS. sdo_ordinate_array

 

The specific fields are not described here. For more information, see the official Oracle documents or related books.

First, use the Oracle type conversion tool (OTT) to convert the sdo_geometry data type to an advanced language source program file.

D: \> Ott userid = Scott/tiger intype = demoin. TPY outtype = demoout. TPY code = CPP hfile =

Sdogeometry. h cppfile = sdogeometry. cpp mapfile = mappings. cpp attraccess = private

After conversion, four C ++ source files and header files are generated.

 

The following code inserts a rectangle.

# Include <iostream> # include <occi. h> # include <assert. h> # include "mappings. H "# include" sdogeometry. H "using namespace ORACLE: occi; using namespace STD; const int sdo_gtype = 2003; int main () {environment * Env = NULL; connection * conn = NULL; statement * stmt = NULL; resultset * rs = NULL; string username = "Scott"; // user name string Password = "tiger"; // password string connstring = "// localhost: 1521/orcl "; // connection string s Ql, strname; int errnum = 0; string errmsg = ""; ENV = environment: createenvironment (Environment: Object); // create an environment variable mappings (ENV ); // register the function try {assert (ENV! = NULL); Conn = env-> createconnection (username, password, connstring); // create a database connection object stmt = Conn-> createstatement (); // create a statement object} catch (sqlexception ex) {errnum = ex. geterrorcode (); errmsg = ex. getmessage (); cout <"error number:" <errnum <Endl; // retrieves the Exception Code cout <"error message:" <errmsg <Endl; // retrieve exception information} // data processing part SQL = "insert into spatial (geoloc) values (: 1)"; try {number srid_null; // sridsrid_null.setnull (); sdo_point_type * point_type = new sdo_point_type (); // struct-> setnull (); vector <number> sdo_elem_info, sdo_ordinates; // element information and coordinate data sdo_elem_info.clear (); sdo_ordinates.clear (); Round (1); sdo_elem_info.push_back (1003); sdo_elem_info.push_back (3); Round (1); Round (1); Round (5); Round (7 ); sdo_geometry * sdo_geometry = new sdo_geometry (); sdo_geometry-> trim (sdo_gtype); sdo_geometry-> trim (srid_null); sdo_geometry-> setsdo_point (point_type ); sdo_geometry-> trim (sdo_elem_info); sdo_geometry-> setsdo_ordinates (sdo_ordinates); stmt-> setsql (SQL); stmt-> setobject (1, sdo_geometry ); // set the object stmt-> executeupdate (); // execute the update operation Delete sdo_geometry;} catch (sqlexception ex) {errnum = ex. geterrorcode (); errmsg = ex. getmessage (); cout <"error number:" <errnum <Endl; // retrieves the Exception Code cout <"error message:" <errmsg <Endl; // retrieve exception information} Conn-> terminatestatement (stmt); // terminate the statement object env-> terminateconnection (conn); // disconnect the database from environment: terminateenvironment (ENV ); // terminate the environment variable return 1 ;}

 

After insertion, the query results are as follows:

SQL> select * from spatial;

 

Geoloc (sdo_gtype, sdo_srid, sdo_point (x, y, z), sdo_elem_info, sdo_ordinates)

Bytes --------------------------------------------------------------------------------------------------------------------------

Sdo_geometry (2003, null, null, sdo_elem_info_array (1, 1003, 3), sdo_ordinate_array (1, 1, 5, 7 ))

 

This only uploads the sample data and tests the actual geospatial data, for example, uploading the shapefile file.

 

Reading is the same as reading relational data, but it can be viewed as an object.

// The following Code reads data: String sqlquery = "select * from spatial"; stmt-> setsql (sqlquery); RS = stmt-> executequery (sqlquery ); while (RS-> next () {sdo_geometry * geometry = (sdo_geometry *) RS-> GetObject (1); cout <"sdo_gtype: "<unsigned int (geometry-> getsdo_gtype () <Endl; // cout <" SRID: "<unsigned int (geometry-> getsdo_srid ()) <Endl ;}

 

 

 

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.