利用Java進行AcrSDE開發執行個體【轉載】

來源:互聯網
上載者:User
利用Java進行AcrSDE開發執行個體【轉載】http://www.gispark.com/html/GIS-Spatial-Database/2007/1227/2002.html

 

利用Java進行AcrSDE開發執行個體:ArcSDE提供了C API和Java API兩種介面。這裡我們只導論如何通過Java API進行arcSDE開發。
開發環境:
JDK 1.5
WIN 插P
Eclipse 3.1+MyEclipse
ArcSDE for Oracle 9i
(1)把arcSDE java API所需要的三個jar包導到web\lib目錄,包括jsde90_sdk.jar,jpe90_sdk.jar ,concurrent.jar;
(2)添加點:
public class AddPointBean {
    public static boolean process(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        Map map=null;
        if (request.getSession().getAttribute(StaticConstant.SESSION_MAP) == null) {
            String strErr = "地圖還沒有初始化";
            request.setAttribute(StaticConstant.REQUEST_ERROR, strErr); 字串3
            return false;
        }
        map=(Map)request.getSession().getAttribute(StaticConstant.SESSION_MAP);
        //串連SDE
        SeConnection conn = null;
        String server = "menglikunm";
        int instance = 5151;
        String database = "ora";
        String user = "sde";
        String password = "sde";
        SeLayer insertLayer=null;
        try {
            conn = new SeConnection(server, instance, database, user, password);

字串1

            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

字串7

                System.out.println(layer.getSpatialColumn());
                if(layer.getName().equalsIgnoreCase("ZHENGFUJIGUAN")){
                    insertLayer=layer;
                }
            }
        } catch (SeException e) {
            e.printStackTrace();
            return false;
        }
        //開始插入資料
        try{ 字串6
            conn.startTransaction();
            String[] cols = new String[2];
            cols[0] = new String("NAME");
            cols[1] = insertLayer.getSpatialColumn();
            SeInsert insert = new SeInsert(conn);
            insert.intoTable(insertLayer.getName(),cols);
            insert.setWriteMode(true);
            SeCoordinateReference coordref =(SeCoordinateReference)insertLayer.getCoordRef();
            SeShape shape = new SeShape(coordref);
            double x=map.toMapPoint(10,10).getX();

字串9

            double y=map.toMapPoint(10,10).getY();
           
            int numPts = 1;
            SDEPoint[] ptArray = new SDEPoint[numPts];
            ptArray[0] = new SDEPoint(x, y);
            shape.generatePoint(numPts, ptArray);
           
            SeRow row = insert.getRowToSet();
            row.setString(0, "測驗點");
            row.setShape(1,shape);
            insert.execute(); 字串7
            insert.close();
            conn.commitTransaction();
            conn.close();
        }catch(Exception ex){
            conn.rollbackTransaction();
            conn.close();
            ex.printStackTrace();
        }
        return true;
    }
}(3)刪除點:
public class DeletePointBean {
    public static boolean process(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        //串連SDE

字串5

        SeConnection conn = null;
        String server = "menglikunm";
        int instance = 5151;
        String database = "ora";
        String user = "sde";
        String password = "sde";
        try {
            conn = new SeConnection(server, instance, database, user, password);
            Vector layerList = conn.getLayers();
            for (int index = 0; index < layerList.size(); index++) {
                SeLayer layer = (SeLayer) layerList.elementAt(index); 字串5
                // 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());
            }
        } catch (SeException e) {
            e.printStackTrace();

字串8

            return false;
        }
        //開始刪除資料
        try{
            conn.startTransaction();
            SeDelete delete=new SeDelete(conn);
            SeObjectId id=new SeObjectId(641);
            delete.byId("ZHENGFUJIGUAN",id);
            conn.commitTransaction();
            delete.close();
        }catch(Exception ex){
            conn.rollbackTransaction(); 字串4
            conn.close();
            ex.printStackTrace();
        }
        return true;
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.