Arcgis Server 图层中实现编辑功能(切记ADF中不能用New实例化对象)

      竟然好几个月没来更新博客了,真为自己羞愧,当然公司禁止了上网也是一大因素吧。希望自己在今后的工作中解决问题后,多记录下,或许回过头来,对自己是

一种帮助,对别人或许也有帮助。
     在上一个项目中,经常要对SDE图层进行查询,修改,导入新要素等操作。由于时间紧迫,我全在后台用AE接口来完成,
项目中前台展示用的是ags for flex,目前9.3的版本没有提供编辑功能的相关接口,当然,总不能等到10.0新版本出来后才做吧。
查阅了无数资料,请教了同行们不少朋友,在asp.net后台用AE的还真没碰到,有朋友提及到用AE是可行的。当然不是最好的。
     我就新建了一个有关GIS操作的类项目,完成了项目的要求,其中编辑的问题,版本的问题,出现无数故障。。。。。
     这个项目不是太急,考虑到服务器端不一定安装Arcengine Runtime .决定采取arcgis server提供的相关接口来进行编辑,然后发布webservice,可实现跨平台调用,

     就算在客户端FLEX里也能完成导入要素的功能。

 

    实现的过程中出现一个错误,花费了不少时间才能完成。。

   在给要素赋值时 pFeature.shape=pGeo;总是提示不支持此类型 ("No support for this geometry type.")

 
   ?pGeo.GeometryType
   esriGeometryPolygon
   ?cFeatureClass.GeometryType
   esriGeometryPolygon


  要素类的类型是esriGeometryPolygon,几何体的类型也是esriGeometryPolygon,分明属于同一类型,怎么就不能赋值咧,
给pGeo添加下监视,里面该有的都有,范围,面积,长度都有值,实在是伤心。。。。
给它赋属性数据时也能成功。
  此时想到,是不是图形存在拓朴错误,比如点坐标不能闭合,有别的自相交等错误咧?写出如下代码后, 发现还是无法赋值。
                if (!pNewPolygon.IsClosed) pNewPolygon.Close();
                ITopologicalOperator2 pTop = pNewPolygon as ITopologicalOperator2;
                pTop.Simplify();

突然想起了原来在ADF中创建远程的object的时候不能用New 来实例化对象,而采取IServerContext.CreateObject的方式。
    话不多说,直接贴代码吧,或者对某些朋友有用,也算给自己温习下。

 

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
1 // 从配置文件中读取连接服务器名以及类型
2   string strServerName = ConfigurationManager.AppSettings[ " serverName " ];
3 string strServerType = ConfigurationManager.AppSettings[ " serverType " ];
4
5
6 ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection m_ServerConnection = null ; // 连接Server
7   ESRI.ArcGIS.Server.IServerContext m_ServerContext = null ;
8 ESRI.ArcGIS.Geodatabase.IWorkspaceEdit m_WorkspaceEdit = null ;
9
10 [WebMethod(Description = " 连接AGS服务器 " )]
11 public bool ConnectServer()
12 {
13 if (m_ServerConnection == null )
14 {
15 m_ServerConnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection();
16 }
17 m_ServerConnection.Host = strServerName;
18 m_ServerConnection.Connect();
19
20 if ( ! m_ServerConnection.IsConnected)
21 return false ;
22 return true ;
23 }
24
25 // 创建 server context
26   ESRI.ArcGIS.Server.IServerObjectManager pServerObjectManager = m_ServerConnection.ServerObjectManager;
27 m_ServerContext = pServerObjectManager.CreateServerContext(cServiceName, strServerType);
28
29 ESRI.ArcGIS.Carto.IMapServer pMapServer = m_ServerContext.ServerObject as ESRI.ArcGIS.Carto.IMapServer;
30 ESRI.ArcGIS.Carto.IMapServerObjects pMapServerObjects = pMapServer as ESRI.ArcGIS.Carto.IMapServerObjects;
31 ESRI.ArcGIS.Carto.IMap pMap = pMapServerObjects.get_Map(pMapServer.DefaultMapName); // 获取地图
32  
33 IDataset pDataset = cFeaClass as IDataset;
34 m_WorkspaceEdit = pDataset.Workspace as ESRI.ArcGIS.Geodatabase.IWorkspaceEdit;
35 if (m_WorkspaceEdit == null ) return " 无法启动编辑 " + pDataset.BrowseName + " 所在的数据库 " ;
36
37 // 分割点坐标赋给远程创建的点,添加到点集合中
38   for ( int i = 0 ; i < strXCoord.Length; i ++ )
39 {
40 // IPoint pNewPt = new PointClass(); // 本地对象
41   IPoint pNewPt = m_ServerContext.CreateObject( " esriGeometry.Point " ) as IPoint;
42 pNewPt.PutCoords(Convert.ToDouble(strXCoord[i]), Convert.ToDouble(strYCoord[i]));
43 pPointCollect.AddPoint(pNewPt, ref pMisObj, ref pMisObj2);
44 }
45
46 m_WorkspaceEdit.StartEditing( false );
47 m_WorkspaceEdit.StartEditOperation();
48
49 IFeature pNewFea = cFeaClass.CreateFeature();
50 // 统一点坐标到西安坐标系
51 IPolygon pNewPolygon = clsFeaOper.ConvertZBX(pPointCollect, tRadCoord);
52 // 拓朴检查,图形修正
53 if ( ! pNewPolygon.IsClosed) pNewPolygon.Close();
54 ITopologicalOperator2 pTop = pNewPolygon as ITopologicalOperator2;
55 pTop.Simplify();
56
57
58 #region 创建线
59 // IPolyline pPolyline = pPointCollect as IPolyline;
60 // pPolyline.Smooth(0.001);
61 #endregion
62 // 给要素赋图形并保存
63 IPolygon pPolygon = pTop as IPolygon;
64 pNewFea.Shape = pPolygon;
65 pNewFea.Store();
66
67 m_WorkspaceEdit.StopEditOperation();
68 m_WorkspaceEdit.StopEditing( true );

 

 

 

转载于:https://www.cnblogs.com/lhjhl/archive/2010/03/31/1701512.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值