posts - 119, comments - 62, trackbacks - 0, articles - 0

利用Java进行AcrSDE开发。

Posted on 2006-04-30 13:21 Kevin Meng 阅读(621) 评论(0)  编辑  收藏
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);
            
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);
            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());
                
if(layer.getName().equalsIgnoreCase("ZHENGFUJIGUAN")){
                    insertLayer
=layer;
                }

            }

        }
 catch (SeException e) {
            e.printStackTrace();
            
return false;
        }

        
//开始插入数据
        try{
            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();
            
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();
            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
        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);
                
// 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();
            
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();
            conn.close();
            ex.printStackTrace();
        }

        
return true;
    }

}
(4)高兴一把,就是这么简单。更多内容请参考arcSDE帮助。

只有注册用户登录后才能发表评论。


网站导航: