当前位置: 代码迷 >> CGI >> 基于ArcGIS Server对ShapeFile资料的编辑功能实现
  详细解决方案

基于ArcGIS Server对ShapeFile资料的编辑功能实现

热度:391   发布时间:2012-07-25 09:43:05.0
基于ArcGIS Server对ShapeFile文件的编辑功能实现
Java代码 复制代码
  1. public ? class ?PointEdit?{ ??
  2. ???????? private ?WebContext?webContext; ??
  3. ???????? public ? void ?AddPoint?(MapEvent?event){ ??
  4. ???????????????? try ?{ ??
  5. ???????????????????????? //得到地图事件所对应的地图对象 ??
  6. ????????????????????????WebMap?webmap=webContext.getWebMap(); ??
  7. ????????????????????????WebPoint?webpoint=(WebPoint)?????????event.getWebGeometry().toMapGeometry(webmap);??????????????????????? ??
  8. ????????????????????????AGSLocalMapResource?mapResource?=?(AGSLocalMapResource)?MapResourceClass.getMapResource(webContext,? 1 ); ??
  9. ????????????????????????IServerContext?context?=?mapResource.getServerContext(); ??
  10. ????????????????????????MapServer?mapServer?=?mapResource.getLocalMapServer(); ??
  11. ???????????????????????? //IMap?maps=?mapServer.getMap(""); ??
  12. ???????????????????????? //ILayer?firstLayer?=?maps.getLayer(Otid); ??
  13. ???????????????????????? //得到图层的空间编辑对象 ??
  14. ????????????????????????IMap?maps=?mapServer.getMap( "" ); ??
  15. ????????????????????????ILayer?layer=maps.getLayer( 0 ); ??
  16. ????????????????????????IFeatureLayer?fLayer?=?(IFeatureLayer)?layer; ??
  17. ????????????????????????IFeatureClass?fc?=?fLayer.getFeatureClass(); ??
  18. ????????????????????????IDataset?ds1= new ?IDatasetProxy(fc); ??
  19. ????????????????????????IWorkspace?pWorkSpace?=?ds1.getWorkspace(); ??
  20. ????????????????????????IWorkspaceEdit?pWorkspaceEdit= new ?IWorkspaceEditProxy(pWorkSpace); ??
  21. ???????????????????????? //开始编辑 ??
  22. ????????????????????????pWorkspaceEdit.startEditing( true ); ??
  23. ????????????????????????pWorkspaceEdit.startEditOperation(); ??
  24. ???????????????????????? //创建新的地图对象 ??
  25. ????????????????????????IFeature?pFeature=fc.createFeature(); ??
  26. ???????????????????????? //将web地图对象转成地图对象 ??
  27. ????????????????????????Point?p=(Point)context.createObject( "esriGeometry.Point" ); ??
  28. ????????????????????????IPoint?pt=(IPoint)context.createObject( "esriGeometry.Point" ); ??
  29. ????????????????????????pt.setX(webpoint.getX()); ??
  30. ????????????????????????pt.setY(webpoint.getY()); ??
  31. ????????????????????????pt.setM( 0 ); ??
  32. ????????????????????????pt.setZ( 0 ); ??
  33. ????????????????????????p=(Point)pt; ??
  34. ???????????????????????? //地图对象赋值 ??
  35. ????????????????????????pFeature.setShapeByRef(p); ??
  36. ???????????????????????? //字段赋值 ??
  37. ????????????????????????pFeature.setValue(fc.findField( "code" ),? 1 ); ??
  38. ???????????????????????? //保存对象 ??
  39. ????????????????????????pFeature.store(); ??
  40. ???????????????????????? //停止编辑 ??
  41. ????????????????????????pWorkspaceEdit.stopEditOperation(); ??
  42. ????????????????????????pWorkspaceEdit.stopEditing( true ); ??
  43. ??
  44. ???????????????????????? //刷新地图 ??
  45. ????????????????????????mapServer.refreshServerObjects(); ??
  46. ????????????????????????webContext.refresh(); ??
  47. ??????????????????????? ??
  48. ????????????????}? catch ?(Exception?gise)?{ ??
  49. ????????????????????????System.out.print( "添加点" ?+?gise.toString()?+? "\n" ); ??
  50. ????????????????????????gise.printStackTrace(); ??
  51. ????????????????}??????????????????????? ??
  52. ????????} ??
  53. } ??
  54. 这是添加点的代码 ??
  55. using?System; ??
  56. using?System.Data; ??
  57. using?System.Configuration; ??
  58. using?System.Web; ??
  59. using?System.Web.Security; ??
  60. using?System.Web.UI; ??
  61. using?System.Web.UI.WebControls; ??
  62. using?System.Web.UI.WebControls.WebParts; ??
  63. using?System.Web.UI.HtmlControls; ??
  64. ??
  65. using?ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools; ??
  66. using?ESRI.ArcGIS.ADF.Web.UI.WebControls; ??
  67. using?ESRI.ArcGIS.ADF.ArcGISServer; ??
  68. using?ESRI.ArcGIS.Server; ??
  69. using?ESRI.ArcGIS.Carto; ??
  70. using?ESRI.ArcGIS.Geometry; ??
  71. using?ESRI.ArcGIS.esriSystem; ??
  72. using?ESRI.ArcGIS.Display; ??
  73. using?System.Collections; ??
  74. using?ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer; ??
  75. using?ESRI.ArcGIS.Geodatabase; ??
  76. ///?<summary> ??
  77. ///?AddPointFeature?的摘要说明 ??
  78. ///?</summary> ??
  79. public ? class ?AddPointFeature?:?IMapServerToolAction ??
  80. { ??
  81. public ?AddPointFeature() ??
  82. { ??
  83. ?? // ??
  84. ?? //?TODO:?在此处添加构造函数逻辑 ??
  85. ?? // ??
  86. } ??
  87. ????#region?IMapServerToolAction?成员 ??
  88. ???? void ?IMapServerToolAction.ServerAction(ToolEventArgs?args) ??
  89. ????{ ??
  90. ???????? //Step1:?取到地图点击画的那个点 ??
  91. ????????ESRI.ArcGIS.ADF.Web.UI.WebControls.Map?mapCtrl; ??
  92. ????????mapCtrl?=?(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control; ??
  93. ????????PointEventArgs?pea?=?(PointEventArgs)args; ??
  94. ????????System.Drawing.Point?screen_point?=?pea.ScreenPoint; ??
  95. ????????MapFunctionality?mapFunc?=?(MapFunctionality)mapCtrl.GetFunctionality( 0 ); ??
  96. ????????MapResourceLocal?mapResLocal?=?mapFunc.Resource?as?MapResourceLocal;???????? ??
  97. ????????IServerContext?pSOC; ??
  98. ????????IMapServer?pMapServer; ??
  99. ????????IMap?pMap; ??
  100. ???????? ??
  101. ????????pSOC?=?mapResLocal.ServerContextInfo.ServerContext; ??
  102. ????????pMapServer?=?pSOC.ServerObject?as?IMapServer; ??
  103. ????????IMapServerObjects?pMapServerObjs?=?pMapServer?as?IMapServerObjects; ??
  104. ????????pMap?=?pMapServerObjs.get_Map(pMapServer.DefaultMapName); ??
  105. ????????ESRI.ArcGIS.ADF.ArcGISServer.MapDescription?mapDesp?=?mapFunc.MapDescription; ??
  106. ????????ESRI.ArcGIS.ADF.Web.Geometry.Point?adf_map_point?=?ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_point,?mapCtrl.Extent,?mapFunc.DisplaySettings.ImageDescriptor.Width,?mapFunc.DisplaySettings.ImageDescriptor.Height); ??
  107. ????????PointN?ags_map_point?=?ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPoint(adf_map_point); ??
  108. ??
  109. ???????? //Step2:插入点到Shp文件中去。要打开WS ??
  110. ???????? //第一个图层是点,第二个图层是线,第三个图层是面。这里就不判断,主要在于功能的实现 ??
  111. ????????ILayer?pLayer?=?pMap.get_Layer( 0 ); ??
  112. ????????IFeatureLayer?pFeatureLyr?=?pLayer?as?IFeatureLayer; ??
  113. ????????IFeatureClass?pFeatCls?=?pFeatureLyr.FeatureClass; ??
  114. ????????IDataset?pDataset?=?pFeatCls?as?IDataset; ??
  115. ????????IWorkspace?pWS?=?pDataset.Workspace; ??
  116. ????????IWorkspaceEdit?pWorkspaceEdit?=?pWS?as?IWorkspaceEdit; ??
  117. ????????pWorkspaceEdit.StartEditing( false ); ??
  118. ????????pWorkspaceEdit.StartEditOperation(); ??
  119. ????????IFeatureBuffer?pFeatureBuffer; ??
  120. ????????IFeatureCursor?pFeatureCuror; ??
  121. ????????IFeature?pFeature; ??
  122. ????????IPoint?pPoint; ??
  123. ????????pFeatureBuffer?=?pFeatCls.CreateFeatureBuffer(); ??
  124. ????????pFeatureCuror?=?pFeatCls.Insert( true ); ??
  125. ????????pFeature?=?pFeatureBuffer?as?IFeature; ??
  126. ????????pPoint?=(IPoint)?pSOC.CreateObject( "esriGeometry.Point" ); ??
  127. ????????pPoint.X?=?ags_map_point.X; ??
  128. ????????pPoint.Y?=?ags_map_point.Y; ??
  129. ????????IGeometry?pPointGeo?=?pPoint?as?IGeometry; ??
  130. ????????pFeature.Shape?=?pPointGeo; ??
  131. ????????pFeatureCuror.InsertFeature(pFeatureBuffer); ??
  132. ???????? ??
  133. ????????pWorkspaceEdit.StopEditOperation(); ??
  134. ????????pWorkspaceEdit.StopEditing( true );???????? ??
  135. ????????mapCtrl.Refresh();????? ??
  136. ????} ??
  137. ????#endregion ??
  138. } ??
  139. ?? ??
  140. 添加线的代码 ??
  141. ??
  142. ??
  143. using?System; ??
  144. using?System.Data; ??
  145. using?System.Configuration; ??
  146. using?System.Web; ??
  147. using?System.Web.Security; ??
  148. using?System.Web.UI; ??
  149. using?System.Web.UI.WebControls; ??
  150. using?System.Web.UI.WebControls.WebParts; ??
  151. using?System.Web.UI.HtmlControls; ??
  152. ??
  153. using?ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools; ??
  154. using?ESRI.ArcGIS.ADF.Web.UI.WebControls; ??
  155. using?ESRI.ArcGIS.ADF.ArcGISServer; ??
  156. using?ESRI.ArcGIS.Server; ??
  157. using?ESRI.ArcGIS.Carto; ??
  158. using?ESRI.ArcGIS.Geometry; ??
  159. using?ESRI.ArcGIS.esriSystem; ??
  160. using?ESRI.ArcGIS.Display; ??
  161. using?System.Collections; ??
  162. using?ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer; ??
  163. using?ESRI.ArcGIS.Geodatabase; ??
  164. ///?<summary> ??
  165. ///?AddPolylineFeature?的摘要说明 ??
  166. ///?</summary> ??
  167. public ? class ?AddPolylineFeature?:?IMapServerToolAction ??
  168. { ??
  169. public ?AddPolylineFeature() ??
  170. { ??
  171. ?? // ??
  172. ?? //?TODO:?在此处添加构造函数逻辑 ??
  173. ?? // ??
  174. } ??
  175. ????#region?IMapServerToolAction?成员 ??
  176. ???? public ? void ?ServerAction(ToolEventArgs?args) ??
  177. ????{ ??
  178. ???????? //Step1:根据客户端定义的动作,将屏幕坐标点转换成地图坐标点 ??
  179. ???????? //并初始化一些常用的参数 ??
  180. ????????ESRI.ArcGIS.ADF.Web.UI.WebControls.Map?mapCtrl; ??
  181. ????????mapCtrl?=?(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control; ??
  182. ????????PolylineEventArgs?peal?=?(PolylineEventArgs)args; ??
  183. ????????System.Drawing.Point[]?screen_points?=?peal.Vectors; ??
  184. ????????MapFunctionality?mapFunc?=?(MapFunctionality)mapCtrl.GetFunctionality( 0 ); ??
  185. ????????MapResourceLocal?mapResLocal?=?mapFunc.Resource?as?MapResourceLocal; ??
  186. ????????ESRI.ArcGIS.ADF.ArcGISServer.MapDescription?mapDesc; ??
  187. ????????mapDesc?=?mapFunc.MapDescription; ??
  188. ????????IServerContext?pSOC; ??
  189. ????????IMapServer?pMapServer; ??
  190. ????????IMap?pMap; ??
  191. ????????pSOC?=?mapResLocal.ServerContextInfo.ServerContext; ??
  192. ????????pMapServer?=?pSOC.ServerObject?as?IMapServer; ??
  193. ????????IMapServerObjects?pMapServerObjs?=?pMapServer?as?IMapServerObjects; ??
  194. ????????pMap?=?pMapServerObjs.get_Map(pMapServer.DefaultMapName); ??
  195. ??
  196. ????????IPointCollection?pPointColl; ??
  197. ????????pPointColl?=?(IPointCollection)pSOC.CreateObject( "esriGeometry.Polyline" ); ??
  198. ???????? for ?( int ?i?=? 0 ;?i?<?screen_points.Length;?i++) ??
  199. ????????{ ??
  200. ????????????IPoint?pPoint; ??
  201. ????????????ESRI.ArcGIS.ADF.Web.Geometry.Point?mappnt?=?ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points,?mapCtrl.Extent,?( int )mapCtrl.Width.Value,?( int )mapCtrl.Height.Value); ??
  202. ????????????pPoint?=?(IPoint)pSOC.CreateObject( "esriGeometry.Point" ); ??
  203. ????????????pPoint.X?=?mappnt.X; ??
  204. ????????????pPoint.Y?=?mappnt.Y; ??
  205. ????????????object?missingVal?=?System.Reflection.Missing.Value; ??
  206. ????????????pPointColl.AddPoint(pPoint,?ref?missingVal,?ref?missingVal); ??
  207. ????????} ??
  208. ????????IGeometry?pPolylineGeo?=?pPointColl?as?IGeometry; ??
  209. ??
  210. ???????? //Step2:插入点到Shp文件中去。要打开WS ??
  211. ???????? //第一个图层是点(0),第二个图层是线(1),第三个图层是面(2)。这里就不判断,主要在于功能的实现 ??
  212. ????????ILayer?pLayer?=?pMap.get_Layer( 1 ); ??
  213. ????????IFeatureLayer?pFeatureLyr?=?pLayer?as?IFeatureLayer; ??
  214. ????????IFeatureClass?pFeatCls?=?pFeatureLyr.FeatureClass; ??
  215. ????????IDataset?pDataset?=?pFeatCls?as?IDataset; ??
  216. ????????IWorkspace?pWS?=?pDataset.Workspace; ??
  217. ????????IWorkspaceEdit?pWorkspaceEdit?=?pWS?as?IWorkspaceEdit; ??
  218. ????????pWorkspaceEdit.StartEditing( false ); ??
  219. ????????pWorkspaceEdit.StartEditOperation(); ??
  220. ????????IFeatureBuffer?pFeatureBuffer; ??
  221. ????????IFeatureCursor?pFeatureCuror; ??
  222. ????????IFeature?pFeature; ??
  223. ????????pFeatureBuffer?=?pFeatCls.CreateFeatureBuffer(); ??
  224. ????????pFeatureCuror?=?pFeatCls.Insert( true ); ??
  225. ????????pFeature?=?pFeatureBuffer?as?IFeature; ??
  226. ????????pFeature.Shape?=?pPolylineGeo; ??
  227. ????????pFeatureCuror.InsertFeature(pFeatureBuffer); ??
  228. ????????pWorkspaceEdit.StopEditOperation(); ??
  229. ????????pWorkspaceEdit.StopEditing( true ); ??
  230. ????????mapCtrl.Refresh();????? ??
  231. ????} ??
  232. ????#endregion ??
  233. } ??
  234. 编辑面的代码 ??
  235. ??
  236. ??
  237. using?System; ??
  238. using?System.Data; ??
  239. using?System.Configuration; ??
  240. using?System.Web; ??
  241. using?System.Web.Security; ??
  242. using?System.Web.UI; ??
  243. using?System.Web.UI.WebControls; ??
  244. using?System.Web.UI.WebControls.WebParts; ??
  245. using?System.Web.UI.HtmlControls; ??
  246. ??
  247. using?ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools; ??
  248. using?ESRI.ArcGIS.ADF.Web.UI.WebControls; ??
  249. using?ESRI.ArcGIS.ADF.ArcGISServer; ??
  250. using?ESRI.ArcGIS.Server; ??
  251. using?ESRI.ArcGIS.Carto; ??
  252. using?ESRI.ArcGIS.Geometry; ??
  253. using?ESRI.ArcGIS.esriSystem; ??
  254. using?ESRI.ArcGIS.Display; ??
  255. using?System.Collections; ??
  256. using?ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer; ??
  257. using?ESRI.ArcGIS.Geodatabase; ??
  258. ///?<summary> ??
  259. ///?AddPolygonFeature?的摘要说明 ??
  260. ///?</summary> ??
  261. public ? class ?AddPolygonFeature?:?IMapServerToolAction ??
  262. { ??
  263. public ?AddPolygonFeature() ??
  264. { ??
  265. ?? // ??
  266. ?? //?TODO:?在此处添加构造函数逻辑 ??
  267. ?? // ??
  268. } ??
  269. ????#region?IMapServerToolAction?成员 ??
  270. ???? public ? void ?ServerAction(ToolEventArgs?args) ??
  271. ????{ ??
  272. ???????? //Step1:根据客户端定义的动作,将屏幕坐标点转换成地图坐标点 ??
  273. ???????? //并初始化一些常用的参数 ??
  274. ????????ESRI.ArcGIS.ADF.Web.UI.WebControls.Map?mapCtrl; ??
  275. ????????mapCtrl?=?(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control; ??
  276. ????????PolygonEventArgs?peag?=?(PolygonEventArgs)args; ??
  277. ????????System.Drawing.Point[]?screen_points?=?peag.Vectors; ??
  278. ????????MapFunctionality?mapFunc?=?(MapFunctionality)mapCtrl.GetFunctionality( 0 ); ??
  279. ????????MapResourceLocal?mapResLocal?=?mapFunc.Resource?as?MapResourceLocal; ??
  280. ????????ESRI.ArcGIS.ADF.ArcGISServer.MapDescription?mapDesc; ??
  281. ????????mapDesc?=?mapFunc.MapDescription; ??
  282. ????????IServerContext?pSOC; ??
  283. ????????IMapServer?pMapServer; ??
  284. ????????IMap?pMap; ??
  285. ????????pSOC?=?mapResLocal.ServerContextInfo.ServerContext; ??
  286. ????????pMapServer?=?pSOC.ServerObject?as?IMapServer; ??
  287. ????????IMapServerObjects?pMapServerObjs?=?pMapServer?as?IMapServerObjects; ??
  288. ????????pMap?=?pMapServerObjs.get_Map(pMapServer.DefaultMapName); ??
  289. ??
  290. ??
  291. ????????IPointCollection?pPointColl; ??
  292. ????????pPointColl?=?(IPointCollection)pSOC.CreateObject( "esriGeometry.Polygon" ); ??
  293. ???????? for ?( int ?i?=? 0 ;?i?<?screen_points.Length;?i++) ??
  294. ????????{ ??
  295. ????????????IPoint?pPoint; ??
  296. ????????????ESRI.ArcGIS.ADF.Web.Geometry.Point?mappnt?=?ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points,?mapCtrl.Extent,?( int )mapCtrl.Width.Value,?( int )mapCtrl.Height.Value); ??
  297. ????????????pPoint?=?(IPoint)pSOC.CreateObject( "esriGeometry.Point" ); ??
  298. ????????????pPoint.X?=?mappnt.X; ??
  299. ????????????pPoint.Y?=?mappnt.Y; ??
  300. ????????????object?missingVal?=?System.Reflection.Missing.Value; ??
  301. ????????????pPointColl.AddPoint(pPoint,?ref?missingVal,?ref?missingVal); ??
  302. ????????} ??
  303. ????????IGeometry?pPolylineGeo?=?pPointColl?as?IGeometry; ??
  304. ??
  305. ???????? //Step2:插入点到Shp文件中去。要打开WS ??
  306. ???????? //第一个图层是点(0),第二个图层是线(1),第三个图层是面(2)。这里就不判断,主要在于功能的实现 ??
  307. ????????ILayer?pLayer?=?pMap.get_Layer( 2 ); ??
  308. ????????IFeatureLayer?pFeatureLyr?=?pLayer?as?IFeatureLayer; ??
  309. ????????IFeatureClass?pFeatCls?=?pFeatureLyr.FeatureClass; ??
  310. ????????IDataset?pDataset?=?pFeatCls?as?IDataset; ??
  311. ????????IWorkspace?pWS?=?pDataset.Workspace; ??
  312. ????????IWorkspaceEdit?pWorkspaceEdit?=?pWS?as?IWorkspaceEdit; ??
  313. ????????pWorkspaceEdit.StartEditing( false ); ??
  314. ????????pWorkspaceEdit.StartEditOperation(); ??
  315. ????????IFeatureBuffer?pFeatureBuffer; ??
  316. ????????IFeatureCursor?pFeatureCuror; ??
  317. ????????IFeature?pFeature; ??
  318. ????????pFeatureBuffer?=?pFeatCls.CreateFeatureBuffer(); ??
  319. ????????pFeatureCuror?=?pFeatCls.Insert( true ); ??
  320. ????????pFeature?=?pFeatureBuffer?as?IFeature; ??
  321. ????????pFeature.Shape?=?pPolylineGeo; ??
  322. ????????pFeatureCuror.InsertFeature(pFeatureBuffer); ??
  323. ????????pWorkspaceEdit.StopEditOperation(); ??
  324. ????????pWorkspaceEdit.StopEditing( true ); ??
  325. ????????mapCtrl.Refresh();????? ??
  326. ????} ??
  327. ????#endregion ??
  328. }?
  相关解决方案