利用Java进行AcrSDE开发实例【转载】

利用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;
    }
}


原文地址:https://www.cnblogs.com/lauer0246/p/1237687.html