Java实现点在线添加的方法

2016-10-20 00:00:00嘉辉 JAVA认证

  Java如何实现点在线添加,下面YJBYS小编为大家整理了相关资料,希望对你有所帮助。内容如下:

  public void addPoint(MapEvent event){

  AGSLocalMapResource res = (AGSLocalMapResource)this.webContext.getResources()。get(“ags0”);

  try{

  // 建立一个工作空间工厂对象,并设置它的参数信息。

  SdeWorkspaceFactory sdewf = (SdeWorkspaceFactory)res.getServerContext()。createObject(SdeWorkspaceFactory.getClsid());

  PropertySet pset = (PropertySet)res.getServerContext()。createObject(PropertySet.getClsid());

  pset.setProperty(“SERVER”, “gxk”);// 服务器名称

  pset.setProperty(“INSTANCE”, “5151”);// 实例名

  pset.setProperty(“USER”, “sa”); // SDE数据表空间的用户名

  pset.setProperty(“PASSWORD”, “sa”);// 密码

  pset.setProperty(“VERSION”, “DBO.gxk”);// SDE数据的版本

  Workspace iws =(Workspace) sdewf.open(pset, 0);

  WebPoint screenPoint = (WebPoint)event.getWebGeometry();

  WebMap mapctrl = event.getWebContext()。getWebMap();

  WebPoint mappnt =WebPoint.toMapPoint(screenPoint, mapctrl.getCurrentExtent(), (int)mapctrl.getWidth(), (int)mapctrl.getHeight());

  Geometry soapgeo=AGSUtil.toAGSGeometry(mappnt);

  String soapString = com.esri.adf.web.ags.util.AGSUtil.serializeStub(soapgeo);

  soapString = soapString.replaceAll(“xsi:type=\”soapenc:Array\“”, “”);

  IPoint mypoint = (IPoint)AGSUtil.deserializeArcObject(soapString, res.getServerContext());

  IWorkspaceEdit wse = (IWorkspaceEdit)iws;

  wse.startEditing(false);

  wse.startEditOperation();

  IFeatureClass featureclass = iws.openFeatureClass(“sde.DBO.Respt”);

  IFeature feature = featureclass.createFeature();

  feature.setShapeByRef((IGeometry)mypoint);

  feature.setValue(feature.getFields()。findField(“NAME”), “kkk”);

  feature.store();

  wse.stopEditOperation();

  wse.stopEditing(true);

  this.webContext.refresh();

  }catch(Exception e){

  e.printStackTrace();

  }

  }

  刷新地图后不能显示新加入的数据的原因是:由于在开始编辑时新打开了一个工作空间,该工作空间并不是浏览器中看到地图所在的工作空间。

[JAVA认证]相关推荐

[JAVA认证]相关栏目推荐
查看更多
上一篇:Linux下RPM软件包管理方法汇总 下一篇:Java中goto实现方法