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

          利用Java進行AcrSDE開發(fā)。

          Posted on 2006-04-30 13:21 Kevin Meng 閱讀(625) 評論(0)  編輯  收藏
          ArcSDE提供了C API和Java API兩種接口。這里我們只導論如何通過Java API進行arcSDE開發(fā)。
          開發(fā)環(huán)境:
          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;
          ????????}

          ????????
          //開始插入數(shù)據(jù)
          ????????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;
          ????????}

          ????????
          //開始刪除數(shù)據(jù)
          ????????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)高興一把,就是這么簡單。更多內(nèi)容請參考arcSDE幫助。

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 信丰县| 贵定县| 文水县| 西峡县| 绵竹市| 连州市| 垫江县| 泸州市| 都安| 福州市| 桑日县| 响水县| 措勤县| 正镶白旗| 禹州市| 福州市| 上林县| 黄大仙区| 惠州市| 长武县| 连平县| 临沭县| 中卫市| 南和县| 巨鹿县| 盐池县| 扶绥县| 凤阳县| 申扎县| 合川市| 思茅市| 义乌市| 马关县| 故城县| 伊宁市| 八宿县| 白沙| 宁国市| 碌曲县| 宁安市| 昭平县|