Abstract: spatial GIS data uploading methods in Oracle Spatial)

Source: Internet
Author: User

Research on spatial GIS data uploading methods in Oracle Spatial)

 

Source: http://blog.sina.com.cn/s/reader_45f260910100999x.html

 

 

Abstract: Oracle Spatial is used to store and manage spatial data, it is easy to solve problems in data sharing, distributed processing, network communication, open development, concurrency control, network integration, cross-platform operation, and data security recovery mechanisms, therefore, it has become an application trend. How to import the spatial data generated in the existing GIS software into the database becomes the primary key aspect of this technology application. Based on this, this article discusses the basic principles of uploading spatial data to Oracle Spatial, this section comprehensively introduces various methods for uploading vector data and raster data in Oracle spatial, this section describes how to manually upload a program using Microsoft's ADO interface, Oracle Spatial's Java API, and occi interface. Finally, the full text conclusions and related suggestions are given.

1 Introduction

Spatial data is the blood of GIS. The management of spatial data directly affects the quality of GIS systems. GIS Spatial Data Management adopts three methods: file-only management of graphical data and attribute data, graphical data file management and attribute data relational database management, and integrated management of spatial data and attribute data. phase. Currently, most GIS software tends to adopt the third management method, that is, the graphical data and attribute data adopt the database management method. For example, Oracle Spatial, DB2 spatial extender, Informix spatial Datablade (currently acquired by IBM), ArcSDE database engine, and MAPGIS mapora engine are used.

Oracle Spatial provides object-relational mode and relational mode to store space data. The former feature is that a spatial table has a type of MDSYS. the sdo_geometry field, which is also the spatial cartridge in the early version of Spatial. It features that each space ry layer corresponds to four tables, they are _ sdolayer, _ sdodim, _ sdogeom, and _

Sdoindex. These tables do not contain attribute data, and the attribute data needs to be connected. Currently, many GIS software companies provide support for Oracle spatial, for example, geomedia 4.0 of Intergraph, MapInfo 6.0 of Mapinfo, mapguide 6.0 of Autodesk, ArcSDE of ESRI, ArcGIS, and MAPGIS 6.5 of Chinese ry companies.

This article mainly studies the principles and specific implementation methods of uploading GIS vector data and raster data to Oracle Spatial, and compares the advantages and disadvantages of several upload methods based on programming practices.

2. How GIS spatial data is uploaded to Oracle Spatial

To upload GIS Spatial Data to Oracle Spatial, the essence is to write the graphic data of spatial data (including vector data and grid data) and the corresponding attribute data into the database table. Therefore, before uploading, you must know how the GIS spatial data format is stored in Oracle spatial.

Each GIS software has its own internal data format and data storage method. Most GIS software does not directly provide users with functions to read and write internal data. To convert data with other software, an external data exchange format is usually defined, such as * of MapInfo *. MIF /*. mid, MAPGIS plaintext format, ESRI shape format (non-ASCII format), and so on. Most of these external interchange formats are ASCII code files. For details about the data structure of these interchange formats, see the instructions published by the company.

Oracle Spatial is an object-relational database. The data type of the bucket is sdo_geometry. With the launch of Oracle 10 Gb, spatial has expanded its topological data model, network data model, and grid data model. Each data model has its own data type, for example, the Type sdo_topogeometry is used to store topology data. Before uploading data, you must understand the attributes and methods of these data types. For more information, see articles 1, 2, and 3.

3. How to upload spatial GIS data to Oracle Spatial

In general, the method of uploading spatial data can be divided into two Methods: Using tools provided by GIS software companies and uploading manually. This section describes how to upload vector and raster data and how to implement it.

3.1 Vector Data upload Method

3.1.1 manual upload

You can use interactive SQL statements to upload GIS spatial data. In this way, you can use various application programming interfaces (such as ADO and ODBC) to upload data, you can call these interfaces using development languages to develop various upload tools based on your application needs. This section describes how to use Microsoft's ADO interface, Oracle Spatial's Java API, and occi interface to upload spatial data.

3.1.1.1 upload using Java API

Application Programing Interface of Oracle Spatial provides three classes: jgeometry, jgeometry. Point, and dataexception. The jgeometry class corresponds to the MDSYS. sdo_geometry object type of Oracle Spatial, jgeometry. Point class corresponds to the MDSYS. sdo_point_type object type, and the dataexception class indicates an exception. The following example demonstrates how to use Java API to write spatial data of GIS to Oracle Spatial:

/// Read spatial data from the database

Resultset rs = statement.exe cutequery ("select geoloc from countries where name = 'China '");

Struct ST = (Oracle. SQL. struct) Rs. GetObject (1 );

// Convert the struct to a geometry object

Jgeometry j_geom = jgeometry. Load (ST );

//... Perform space operations on a space object or create a new space object...

/// Objects stored in the database

Preparedstatement PS = connection. preparestatement ("Update countries set geometry =? Where name = 'China '");

// Convert a jgeometry object to a database structure.

Struct OBJ = jgeometry. Store (j_geom, connection );

PS. setobject (1, OBJ );

Ps.exe cute ();

3.1.1.2 occi upload example

This upload example is a complete example program that uses occi (Oracle C ++ call interface) to upload space data. First, use the Oracle database data type translation tool Ott (Oracle type translator) Translation types MDSYS. sdo_point_type and MDSYS. sdo_geometry, and enter them in the command line,

Ott attraccess = private code = CPP cppfile = spatial_classeso.cpp hfile = spatial_classesh.h intype = paimapfile = spatial_classesm.cpp mapfunc = registerclasses userid = Scott/tiger @ GIS

After the command is successfully executed, four files are generated, namely spatial_classesh.h, spatial_classeso.cpp, spatial_classesm.h, and spatial_classesm.cpp;

Then, create a space table (that is, a table storing space data) Spatial in Scott user mode. The SQL statement is as follows:

Create Table spatial (geoloc MDSYS. sdo_geometry );

Finally, use VC ++ to create a project, and add the previously translated files spatial_classesh.h, spatial_classeso.cpp, spatial_classesm.h, and spatial_classesm.cpp to the project. The content of the main file is,

# Include

# Include

# Include

# Include

# Include "spatial_classesh.h"

# Include "spatial_classesm.h"

Using namespace STD;

Using namespace ORACLE: occi;

Const int sdo_gtype_2dpoint = 2001;

Const int sdo_gtype_2dpolygon = 2003;

Const int sdo_etype_polygon = 1003;

Const int sdo_interpretation_rectangle = 3;

Void main ()

{Try

{// Initialize the environment variable in Object Mode

Environment * Env = environment: createenvironment (Environment: Object );

Registerclasses (ENV); // registers the type function.

Connection * conn = env-> createconnection ("Scott", "Tiger", "GIS ");

Try

{Statement * stmt = Conn-> createstatement ("insert into spatial (geoloc) values (: 1 )");

  • // Bucket object

    Number srid_null;

    Sdopointtype * point_null = new sdopointtype ();

    Point_null-> setnull ();

    Sdogeometry * spatial_obj = new sdogeometry (); // create an object

    Spatial_obj-> setsdo_gtype (sdo_gtype_2dpolygon );

    Spatial_obj-> setsdo_srid (srid_null); // do not set the Coordinate System

    Spatial_obj-> setsdo_point (point_null); // set the vertex object to null.

    Vector elem_info, ordinates;

    Elem_info.clear (); // clear elem_info

    Ordinates. Clear (); // clear ordinates

    // Store the elem_info object

    Elem_info.push_back (1); elem_info.push_back (sdo_etype_polygon );

    Elem_info.push_back (sdo_interpretation_rectangle );

    Spatial_obj-> setsdo_elem_info (elem_info );

    // Store the rectangle. ordinates can store parameters with more than 4000 characters, while ADO can store parameters with less than 4000 characters.

    Ordinates. push_back (1); ordinates. push_back (1); // (1, 1)

    Ordinates. push_back (5); ordinates. push_back (7); // (5, 7)

    Spatial_obj-> setsdo_ordinates (ordinates );

    Stmt-> setobject (1, spatial_obj );

    Stmt-> executeupdate ();

    Delete spatial_obj; // release the object

    Conn-> terminatestatement (stmt );}

    Catch (sqlexception & Ex)

    {Env-> terminateconnection (conn );

    Environment: terminateenvironment (ENV );

    Throw ;}

    Env-> terminateconnection (conn );

    Environment: terminateenvironment (ENV );}

    Catch (sqlexception & Ex)

    {Cout <"error running Demo:" <ex. getmessage () <Endl ;}}

    After compilation, the project stores a rectangle in the spatial table of Oracle Spatial. You can expand the project to store the public format of GIS software in ASCII code format to the database, such as * of MapInfo *. MIF /*. mid format, MAPGIS vertices, lines, areas, and network file plaintext data.

    3.1.1.3 upload using VB and ADO

    There are also differences between various application interfaces. If ADO is used, there may be situations where parameter passing does not meet the requirements. For example, the following uses ADO statements in VB6.0,

    Set adocommand = nothing

    Adocommand. commandtype = ad1_text

    Adocommand. commandtext = "insert into spatialtable_name (spatial_column) values" & spatialdata

    Adocommand. activeconnection = adoconnection

    Adocommand. Execute

    The commandtext attribute of the ADO command object cannot be passed if it contains more than 4000 characters. Therefore, objects in a long space need to be truncated. Therefore, using the ADO interface for upload is not the best choice. If you select the application programming interface provided by Oracle (in addition to the previously mentioned oo4o and OCI), this problem will not occur. Therefore, we recommend that you use the application programming interface provided by Oracle to develop the upload program.

    3.1.2 upload using tools

    Currently, many GIS software companies provide tools for uploading spatial data to Oracle Spatial, such as easyloader, ArcSDE, and MAPGIS.

    3.1.2.1 easyloader

    Easyloader is an upload tool provided by MapInfo. However, this tool only supports uploading *. Tab data in MapInfo format. This tool provides command line upload and window upload methods. The tool writes data to the database by calling the OCI (Oracle call interface) at the underlying layer. The biggest advantage of using easyloader to upload spatial data to Oracle Spatial is that the uploaded spatial data is stored in object-relational mode, which fully utilizes the advantages of Oracle Spatial's object-relational mode. After MapInfo Professional is installed, this tool is installed by default. You can find this tool in the % MapInfo % "Tools directory. In addition, this free tool is also available on the official website of MapInfo.

    3.1.2.2 SQL * loader and shp2sdo

    SQL * loader reads ASCII code data based on commands received from the control file and puts the data into the Oracle database. The control file notifies SQL * Where the loader data should be stored and describes all types of data loaded into the Oracle database. SQL * loader can also filter data (that is, do not load unsuitable data) and load data into multiple tables, A unique keyword or operation data is generated before data is placed into an oracle table.

    Shp2sdo is a command line tool provided by Oracle to convert ESRI *. SHP files into control files and data files that can use SQL * loader. This tool can not only convert *. SHP to object-link format, but also to link format. This tool can be downloaded free of charge from the Oracle website.

    With SQL * loader and shp2sdo, you can upload the ESRI shape file to Oracle spatial.

    3.1.2.3 tools provided by ArcSDE and MAPGIS

    If you have purchased an ESRI ArcSDE, you can use the arctoolbox tool to upload ESRI data through the ArcSDE spatial database engine. Like ArcMap or arccatalog, arctoolbox is an important member of the ArcGIS family and is responsible for data import and export. In addition to ESRI format data (such as shapefile and covage files), arctoolbox also provides data conversion for common file formats such as e00 and DWG. During data conversion, you can set conversion parameters based on actual needs, such as the field name of the spatial data table and the maximum value of the spatial index coordinate. Arctoolbox provides us with a good data conversion tool. Similarly, if MAPGIS is 6.5 or later, you can use the attributes library management subsystem of MapGIS and the tools provided by the editing subsystem to upload spatial data of MAPGIS. Although ArcSDE is logically oriented to object storage, it physically uses a pure relational table of oracle. Therefore, the current versions of these two tools only support the relational mode, that is, the spatial cartridge mode.

    3.2 how to upload Raster Data

    Since Oracle 10 Gb, Oracle Spatial has added a module for storing raster data. It also provides Java APIs for uploading raster data, PL/SQL APIs, And the upload tool georasterloader. The following describes how to use georasterloader to upload raster data:

    1) Create Table S (jpg mdsys. sdo_georaster );

    2) Call sdo_geor_utl.createdmltrigger ('s S', 'jpg ');

    3) Create Table rdt1 of MDSYS. sdo_raster (primary key (rasterid, pyramidlevel, bandblocknumber, rowblocknumber, columnblocknumber ));

    4) insert into S values (MDSYS. sdo_geor.init ('rdt1 '));

    5) Select JPG from S;

    Return Value: sdo_georaster (null, null, 'rdt1', 22, null)

    6) commit;

    7) use the following command in the command line tool of the operating system to upload the Raster image "C:" test.jpg ",

    Java georasterloader gis01 GIS 1521 Scott tiger thin 32 t JPEGs jpg "blocking = true, blocksize = (256,256, 1)" "C:" test.jpg, 22, rdt1 ";

    8) after the upload is successful, you can also use georasterviewer to browse the Raster image and enter the following command in the command line tool of the operating system,

    Java georasterloader gis01 GIS 1521 Scott tiger thin 32 t;

    When uploading raster data, because the current oracle10.1.2 version uses the raster data model does not support Chinese characters, you must select English when installing Oracle 10 Gb, you cannot use Chinese by default.

    4 Conclusion

    (1) Use Oracle Spatial to store and manage spatial data, it is easy to solve problems in data sharing, distributed processing, network communication, open development, concurrency control, network integration, cross-platform operation, and data security recovery mechanisms, therefore, it has become an application trend. How to import the spatial data generated in the existing GIS software into the database becomes the primary key aspect of this technology application.

    (2) to upload GIS Spatial Data to Oracle Spatial, the essence is to write the graphic data of spatial data (including vector data and grid data) and the corresponding attribute data into the database table. Fully understand the storage method of imported GIS data and the data type of Oracle Spatial and its object attributes and methods are the basis for the implementation of the upload program.

    (3) You can use the tools provided by GIS or manually write programs to upload data. In the selection of specific methods: If the GIS software provides the corresponding upload tools, we recommend that you use these tools for upload, in this way, you can use the corresponding secondary development component to develop applications based on Oracle Spatial (for example, you have uploaded * using easyloader *. after the tab file, you can use the Oracle Spatial Data Source in MapX of MapInfo and mapxtreme for Java). If there is no corresponding upload tool, you can develop upload tools by using interfaces such as ADO, OCI, occi, oo4o, and Java APIs.

    (4) in the implementation of the Java API, occi, and ADO interfaces described in this article, the command object of the ADO interface cannot pass the value when the commandtext attribute has more than 4000 characters. Therefore, a long space object will be truncated. Therefore, we recommend that you use the Java API and occi interface provided by Oracle to develop the upload program.

    (5) The Oracle Spatial option of Oracle10g adds a module for storing raster data, and provides Java APIs, PL/SQL APIs, And the upload tool georasterloader for uploading raster data. You can use georasterloader to upload raster data. However, the Raster Data Model in oracle10.1.2 does not support Chinese characters, therefore, we recommend that you choose to use English instead of the default Chinese language.

 

 

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.