ArcSDE Java API__Java

來源:互聯網
上載者:User

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

ArcSDE Java API 提供了一個開放的、高層次的編程介面,以處理與分析空間資訊。它包含了三個 java 包: Client 包、 Geometry 包、以及 Projection 包。

Client 包提供了實現 ArcSDE 伺服器相關的功能的類。利用這個包建立的應用程式,能建立一個到 ArcSDE 執行個體的串連,查詢一個層,或者與 ArcSDE 伺服器進行通訊。

Geometry 包提供了實現 OGC (開源 GIS )幾何學功能介面的類。

Projection 包提供了定義一個座標系統與在不同座標系統中轉換的功能的類。

下面的主題對 ArcSDE Java API 的功能進行了大體的介紹。 設定 API

在 ArcSDE 用戶端安裝的時候安裝了下列檔案:

1.      jsde90_sdk.jar- 包含了 ArcSDE 用戶端 , 幾何學功能以及 SG Java API 的類檔案。

2.        jpe90_sdk.jar – 包含了 ArcSDE Projection Engine Java API 的類檔案。

3.        concurrent.jar – 這個檔案在使用 PeCSTransformationX() 時必須要用到 , PeCSTransformationX() 的功能是轉換座標系統。

4.        sdejavautil.dll (Windows 平台下 ) - contains the native code portion of the com.esri.sde.sdk.client.SeInstance start function.

5.        libsdejavautil.so (Unix platforms only, libsdejavautil.sl on HP-UX) - contains the native code portion of the com.esri.sde.sdk.client.SeInstance start function.

Java Doc(HTML 格式的 API 功能參考文檔 ) 可以在 ArcSDE Developer Help 中連結到,這個文檔可以在 ArcSDE 用戶端安裝的 CD 上以及 ESRI的支援人員網站 中找到。

要建立一個使用 ArcSDE java API 的應用程式,你必須要在系統中安裝 Java 2 Standard Edition SDK , 1.4.0 版本以上。你還必須在你的 CLASSPATH 環境變數中加上 jsde90_sdk.jar, jpe90_sdk.jar and concurrent.jar 的檔案路徑。如果你還要使用到 com.esri.sde.sdk.client.SeInstance 的 Start 函數,你還要往你的系統路徑( Windows 平台 system path ;所有的 Unix 平台 system library path )中添加 sdejavautil library 。 串連到 ArcSDE

使用 ArcSDE 軟體的第一步是建立一個 ArcSDE 伺服器串連。 SeConnection 類就是用來建立一個串連的。下面是一個建立串連的例子:

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();
        }
    }

注意: instance 參數是 ArcSDE 伺服器的連接埠號碼。例如: 5151 ,而不是 esri_sde 。

 

 串連與資料庫資訊

SeConnection 類還提供了取得 ArcSDE 伺服器資訊的方法,這些資訊包括:伺服器的版本以及串連的資訊。使用 SeConnection 類還可以取得儲存在 RDBMS 上的資料的相關資訊。下面的例子展示了如何取得儲存與 ArcSDE 資料庫內的的圖層列表資訊(假設串連已經建立)。

    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() );
    }

SeLayer 對象包含了圖層的所有相關資訊 ArcSDE Java API 函數參考中還列出了其他的取得 ArcSDE layer 的屬性的方法.

Fetching data

資料從一張表或者一個 layer 中查詢得出。 SeQuery 對象則是用於準備並執行一個查詢操作,建立並執行一個查詢的步驟如下:

      1. 建立一個 SeSqlConstruct 對象,這個對象中有想要查詢的 table/layer 的名字。你也可以在 SeSqlConstruct 的建構函式中指定一個 where 查詢語句。

            SeLayer layer = new SeLayer( conn, layerName, spatialColumn );

            SeSqlConstruct sqlConstruct = new SeSqlConstruct( layer.getName() );

      2. 建立一個 String 數組以儲存要查詢的表的列名。

            String[] cols = new String[2];

            cols[0] = new String("ColumnOneName");

            cols[1] = layer.getSpatialColumn();

      3. 定義,準備並執行查詢。

            // Create a query stream between the client and server

            SeQuery query = new SeQuery( conn, cols, sqlConstruct );

            query.prepareQuery();

            query.execute();

      4. 取查詢結果的第一行存入 SeRow 對象中。

            SeRow row = query.fetch();

      5. 取得 SeRow 的列結構。

             // Get the definitions of all the columns retrieved

            SeColumnDefinition[] colDefs = SeRow.getColumns();

      6. 先擷取第一列的資料類型,然後擷取該單元上的資料。

            // 擷取第一列的資料類型。

            int colNum = 0;

            int dataType = colDefs[colNum].getType;

            // 假定資料類型只有 String 和 Shape 兩種。

            // 可以自己添加一些語句以支援 ArcSDE 列的所有資料類型。

            // ( See 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);

                  // 調用一個函數以擷取 Shape 的屬性。

                  break;

            }

     

      7. 關閉查詢。

            query.close();

     

注意 : 為了取出查詢結果所有的行,可以反覆的調用 query.fetch 直至 SeRow 對象返回為空白值為止。

插入資料

可以使用 SeInsert 類來往一張表或者圖層中插入資料。插入資料的步驟如下:

      1. 建立一個 String 對象,以儲存要添加資料的表的列名。注意數組索引值;這些索引值將在 SeRow.set* 中使用到。 String 類型的列的索引值是 0 ,而 Shape 類型的列的索引值是 1.

               String[] cols = new String[2];

               cols[0] = new String("ColumnOneName");

               cols[1] = layer.getSpatialColumn();

      2. 使用當前的串連控制代碼 Connection conn, 建立一個 SeInsert 對象 . 這將建立一個從用戶端到伺服器的 Insert 資料流 (Stream) 。然後根據表或圖層的列名來插入資料,設定 SeInsert 對象為可寫入模式 (setWriteMode) 。

               SeInsert insert = new SeInsert(conn);

               insert.intoTable(layer.getName(),cols);

               insert.setWriteMode(true);

      3. 擷取 SeInsert 對象中將要添加的 SeRow 對象。然後設定要插入的資料,這一步用到 SeRow.set* 方法。利用第一步中確定的索引值來作為 set* 方法中的 columnPosition 參數。

               SeRow row = insert.getRowToSet();

               row.setString(0, "Shape Number One");

               row.setShape(1,shape);

      4. 調用 SeInsert 對象的 execute() 方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.