ArcSDE Java Api__java

Source: Internet
Author: User

http://edndoc.esri.com/arcsde/9.3/api/japi/docs/index.html Introduction

The ArcSDE Java API provides an open, high-level programming interface for processing and analyzing spatial information. It contains three Java packages: the Client package, the Geometry package, and the projection package.

The Client package provides a class that implements the functionality associated with the ArcSDE server. An application built with this package can create a connection to a ArcSDE instance, query a layer, or communicate with a ArcSDE server.

The Geometry package provides classes that implement the interface of OGC (open source GIS) geometry functionality.

The projection package provides classes that define a coordinate system and the functions that are converted in different coordinate systems.

The following topics outline the functionality of the ArcSDE Java API. Set API

The following files were installed when the ArcSDE client was installed:

1. jsde90_sdk.jar-contains class files for ArcSDE clients, geometry functions, and SG Java APIs.

2. jpe90_sdk.jar– contains class files for the ArcSDE projection Engine Java API.

3. concurrent.jar– This file must be used when using Pecstransformationx (), and the function of Pecstransformationx () is to transform the coordinate system.

4. Sdejavautil.dll (Windows Platform)-contains the native code portion of the Com.esri.sde.sdk.client.SeInstance star t function.

5. libsdejavautil.so (Unix platforms only, LIBSDEJAVAUTIL.SL on HP-UX)-contains the native code portion of the CO M.esri.sde.sdk.client.seinstance start function.

Java Doc (HTML-formatted API feature reference documentation) can be linked in ArcSDE Developer help, which can be found on the ArcSDE client-installed CD and on ESRI's technical support website.

To build an application that uses the ArcSDE Java API, you must install the Java 2 Standard Edition SDK in the system, 1.4.0 version above. You must also add Jsde90_sdk.jar to your CLASSPATH environment variable, jpe90_sdk.jar and Concurrent.jar file path. If you also want to use the Start function of com.esri.sde.sdk.client.SeInstance, you will also go to your system path (Windows platforms system path; All Unix Platform System library Path ), add the Sdejavautil library. Connect to ArcSDE

The first step in using the ArcSDE software is to establish a ArcSDE server connection. The Seconnection class is used to establish a connection. Here is an example of establishing a connection:

public static void Main (String args[]) throws Exception {

Seconnection conn = null;

String Server = "Sdeserver";

int instance = 5151;

String database = "Sdedb";

String user = "User";

String password = "passwd";

try {

conn = new Seconnection (server, instance, database, user, password); 

}catch (Seexception e) {

E.printstacktrace ();

}

}

Note: The instance parameter is the port number of the ArcSDE server. For example: 5151, not esri_sde.

 

Connection and database information

The Seconnection class also provides methods for obtaining ArcSDE server information, including the version of the server and information about the connection. You can also use the Seconnection class to obtain information about the data stored on the RDBMS. The following example shows how to get a list of layers stored in the ArcSDE database (assuming the connection is already established).

Vector layerlist = Conn.getlayers ();

for (int index = 0; index < layerlist.size (); index++) {

Selayer layer = (selayer) layerlist.elementat (index);

Displays the layer ' s name

System.out.println (Layer.getname ());

Displays the layer ' s ID

System.out.println (Layer.getid (). Longvalue ());

Displays the layer ' s spatial column name

System.out.println (Layer.getspatialcolumn ());

}

The Selayer object contains all the relevant information about the layer ArcSDE the Java API function Reference also lists other methods for obtaining ArcSDE layer properties.

Fetching Data

The data is queried from a table or a layer. The Sequery object is used to prepare and execute a query operation, and the steps to establish and execute a query are as follows:

1. Create a Sesqlconstruct object that has the name of the table/layer you want to query. You can also specify a where query statement in the Sesqlconstruct constructor.

Selayer layer = new Selayer (conn, layername, Spatialcolumn);

Sesqlconstruct sqlconstruct = new Sesqlconstruct (Layer.getname ());

2. Create a String array to store the column names of the tables you want to query.

string[] cols = new string[2];

Cols[0] = new String ("Columnonename");

COLS[1] = Layer.getspatialcolumn ();

3. Define, prepare and execute the query.

Create a query stream between the client and server

Sequery query = new Sequery (conn, cols, sqlconstruct);

Query.preparequery ();

Query.execute ();

4. The first line of the query result is stored in the Serow object.

Serow row = Query.fetch ();

5. Obtain the Serow of the column structure.

Get the definitions of the columns retrieved

secolumndefinition[] Coldefs = Serow.getcolumns ();

6. Get the data type of the first column, and then get the data on that cell.

Gets the data type of the first column.

int colnum = 0;

int dataType = Coldefs[colnum].gettype;

Assume that the data type is only String and Shape two species.

You can add some statements yourself to support all data types of the ArcSDE column.

(Working with Layers Example)

Switch (dataType) {

Case secolumndefinition.type_string:

System.out.println (Coldef.getname () + row.getstring (colnum));

Break

Case Secolumndefinition.type_shape:

System.out.println (Coldef.getname ());

Seshape shape = Row.getshape (Colnum);

Call a function to get the properties of the Shape.

Break

}

7. Close the query.

Query.close ();

Note: To remove all rows from the query result, you can repeatedly invoke Query.fetch until the Serow object returns to a null value.

Inserting Data

You can use the Seinsert class to insert data from one table or layer. The steps for inserting data are as follows:

1. Create a String object to store the column names of the tables that you want to add data to. Note Array index values, which are used in serow.set*. The index value of a String type column is 0, and the index value of a Shape type column is 1.

string[] cols = new string[2];

Cols[0] = new String ("Columnonename");

COLS[1] = Layer.getspatialcolumn ();

2. Create a Seinsert object using the current connection handle Connection Conn. This creates an Insert data stream (stream) from the client to the server. Then insert the data based on the table or layer's column name, and set the Seinsert object to be writable (Setwritemode).

Seinsert insert = new Seinsert (conn);

Insert.intotable (Layer.getname (), cols);

Insert.setwritemode (TRUE);

3. Gets the Serow object that will be added in the Seinsert object. Then set the data to be inserted, this step is to use the Serow.set* method. Use the index value determined in the first step as the ColumnPosition parameter in the Set* method.

Serow row = Insert.getrowtoset ();

Row.setstring (0, "Shape number One");

Row.setshape (1,shape);

4. Invoke the Execute () method of the Seinsert object

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.