Arcengine地图编辑工具条_第1页
Arcengine地图编辑工具条_第2页
Arcengine地图编辑工具条_第3页
Arcengine地图编辑工具条_第4页
Arcengine地图编辑工具条_第5页
已阅读5页,还剩46页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、using System;using System.Collections.Generic;using System.Text;using System.Reflection;using System.IO;using System.Windows.Forms;using System.Runtime.InteropServices;using System.Runtime.Serialization.Formatters.Binary;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.Geometry;us

2、ing ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.DataSourcesGDB;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.Controls;namespace LGGIS.MapEdit public class ArcgisEditor / / 使用本类可以新建点、线、面 / 移动点、线、面 / 编辑线、面的节点 / 使用时需设置Map和CurrentLayer / private IMapControl3 m_pMapControl; private ILayer m_pCurrentLayer;

3、 private IMap m_pMap; private IFeature m_pEditFeature; private IPoint m_pPoint; private IDisplayFeedback m_pFeedback; /private ISelectionTracker m_pSelectionTracker; private bool m_bInUse; private IPointCollection m_pPointCollection; private ISelection m_Selection = null; private IGeometryCollection

4、 m_GeometryCollection = null; public static IEnumFeature SelEnumFeature = null; private IArray m_ElementArray = new ArrayClass(); public IMapControl3 MapControl get return m_pMapControl; set m_pMapControl = value; / / 当前图层 / public ILayer CurrentLayer get return m_pCurrentLayer; set m_pCurrentLayer

5、= (ILayer)value; / / 地图对象 / public IMap Map get return m_pMap; set m_pMap = (IMap)value; / / 选中的要素 / public ISelection Selection get return m_Selection; set m_Selection = value; / / 构造函数 / public ArcgisEditor() public bool IsStartEdit() IWorkspaceEdit pWorkspaceEdit; IFeatureClass pFeatureCls; IFeat

6、ureLayer pFeatureLyr; bool pIsStart = false; for (int i = 0; i m_pMapControl.LayerCount; i+) pFeatureLyr = m_pMapControl.Map.get_Layer(i) as IFeatureLayer; if (pFeatureLyr = null) continue; pFeatureCls = pFeatureLyr.FeatureClass; pWorkspaceEdit = (IDataset)pFeatureCls).Workspace as IWorkspaceEdit; i

7、f (pWorkspaceEdit.IsBeingEdited() = true) pIsStart = true; break; return pIsStart; public ILayer getCurrentLayer() ILayer pLayer = CheckEditingFeatureLayer() ; return pLayer; public ILayer CheckEditingFeatureLayer() IWorkspaceEdit pWorkspaceEdit; IFeatureClass pFeatureCls; IFeatureLayer pFeatureLyr;

8、 ILayer pLayer = null; for (int i = 0; i m_pMapControl.LayerCount; i+) if (m_pMapControl.Map.get_Layer(i) is IFeatureLayer) pFeatureLyr = m_pMapControl.Map.get_Layer(i) as IFeatureLayer; if (pFeatureLyr = null) continue; pFeatureCls = pFeatureLyr.FeatureClass; pWorkspaceEdit = (IDataset)pFeatureCls)

9、.Workspace as IWorkspaceEdit; if (pWorkspaceEdit.IsBeingEdited() = true) pLayer = pFeatureLyr as ILayer; ILayer plyr = m_pMapControl.CustomProperty as ILayer; if (plyr != null & (IDataset)(IFeatureLayer)plyr).FeatureClass).Workspace = (IDataset)pFeatureCls).Workspace) pLayer = plyr; break; return pL

10、ayer; / / 开始编辑,使工作空间处于可编辑状态 / 在进行图层编辑前必须调用本方法 / public void StartEditing() try if (m_pCurrentLayer = null) return; if (!(m_pCurrentLayer is IGeoFeatureLayer) return; IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer; IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass; if (pDataset =

11、 null) return; / 开始编辑,并设置Undo/Redo 为可用 IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace; if (!pWorkspaceEdit.IsBeingEdited() pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.EnableUndoRedo(); catch (Exception e) Console.WriteLine(e.Message.ToString(); / / 停止编辑,并将以前的编辑结果保存到数据文件中。 /

12、 public void StopEditing() bool bHasEdits = false; bool bSave = false; try if (m_pCurrentLayer = null) return; IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer; if (pFeatureLayer.FeatureClass = null) return; IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass; if (pDataset = null) r

13、eturn; /如果数据已被修改,则提示用户是否保存 IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace; if (pWorkspaceEdit.IsBeingEdited() pWorkspaceEdit.HasEdits(ref bHasEdits); if (bHasEdits) DialogResult result; result = MessageBox.Show(是否保存已做的修改?, 提示, MessageBoxButtons.YesNo); if (result = DialogResult.Y

14、es) bSave = true; pWorkspaceEdit.StopEditing(bSave); m_pMap.ClearSelection(); IActiveView pActiveView = (IActiveView)m_pMap; pActiveView.Refresh(); catch (Exception e) Console.WriteLine(e.Message.ToString(); public bool HasEdits() IWorkspaceEdit pWorkspaceEdit; IFeatureLayer pFeatureLayer = m_pCurre

15、ntLayer as IFeatureLayer; pWorkspaceEdit = (IDataset)pFeatureLayer.FeatureClass).Workspace as IWorkspaceEdit; bool blHasEdits = false; pWorkspaceEdit.HasEdits(ref blHasEdits); return blHasEdits; / / 检查工作空间中是否有数据处于编辑状态 / / 是否正在编辑 public bool InEdit() try if (m_pCurrentLayer = null) return false; IFea

16、tureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer; if (pFeatureLayer.FeatureClass = null) return false; IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass; if (pDataset = null) return false; IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace; if (pWorkspaceEdit.IsBeingEd

17、ited() return true; return false; catch (Exception e) Console.WriteLine(e.Message.ToString(); return false; / / 新建对象方法 / 当前图层为点图层时,每调用一次就新点一个点对象 / 当前图层为线图层或面图层时,第一次调用开始新建对象,并添加当前点, / 以后每调用一次,即向新对象中添加一个点,调用NewFeatureEnd方法完成对象创建 / 在Map.MouseDown事件中调用本方法 / / 鼠标X坐标,屏幕坐标 / 鼠标Y坐标,屏幕坐标 public void NewFeatu

18、reMouseDown(int x, int y) INewPolygonFeedback pPolyFeed; INewLineFeedback pLineFeed; try if (IsStartEdit() = true) if (m_pCurrentLayer = null) return; if (!(m_pCurrentLayer is IGeoFeatureLayer) return; IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer; if (pFeatureLayer.FeatureClass = nul

19、l) return; IActiveView pActiveView = (IActiveView)m_pMap; IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); / 如果是新开始创建的对象,则相应的创建一个新的Feedback对象; / 否则,向已存在的Feedback对象中加点 if (!m_bInUse) m_pMap.ClearSelection(); /清除地图选中对象 switch (pFeatureLayer.FeatureClass.ShapeType) case

20、 esriGeometryType.esriGeometryPoint: CreateFeature(pPoint); break; case esriGeometryType.esriGeometryMultipoint: m_bInUse = true; m_pFeedback = new NewMultiPointFeedbackClass(); INewMultiPointFeedback pMPFeed = (INewMultiPointFeedback)m_pFeedback; m_pPointCollection = new MultipointClass(); pMPFeed.

21、Start(m_pPointCollection, pPoint); break; case esriGeometryType.esriGeometryPolyline: m_bInUse = true; m_pFeedback = new NewLineFeedbackClass(); pLineFeed = (INewLineFeedback)m_pFeedback; pLineFeed.Start(pPoint); break; case esriGeometryType.esriGeometryPolygon: m_bInUse = true; m_pFeedback = new Ne

22、wPolygonFeedbackClass(); pPolyFeed = (INewPolygonFeedback)m_pFeedback; pPolyFeed.Start(pPoint); break; if (m_pFeedback != null) m_pFeedback.Display = pActiveView.ScreenDisplay; else if (m_pFeedback is INewMultiPointFeedback) object obj = Missing.Value; m_pPointCollection.AddPoint(pPoint, ref obj, re

23、f obj); else if (m_pFeedback is INewLineFeedback) pLineFeed = (INewLineFeedback)m_pFeedback; pLineFeed.AddPoint(pPoint); else if (m_pFeedback is INewPolygonFeedback) pPolyFeed = (INewPolygonFeedback)m_pFeedback; pPolyFeed.AddPoint(pPoint); catch (Exception e) Console.WriteLine(e.Message.ToString();

24、/基于捕捉新建要素 public void NewFeatureMouseDownBySnapPoint(IPoint dpoint) INewPolygonFeedback pPolyFeed; INewLineFeedback pLineFeed; try if (m_pCurrentLayer = null) return; if (!(m_pCurrentLayer is IGeoFeatureLayer) return; IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer; if (pFeatureLayer.Fe

25、atureClass = null) return; IActiveView pActiveView = (IActiveView)m_pMap; IPoint pPoint = dpoint; / 如果是新开始创建的对象,则相应的创建一个新的Feedback对象; / 否则,向已存在的Feedback对象中加点 if (!m_bInUse) m_pMap.ClearSelection(); /清除地图选中对象 switch (pFeatureLayer.FeatureClass.ShapeType) case esriGeometryType.esriGeometryPoint: Creat

26、eFeature(pPoint); break; case esriGeometryType.esriGeometryMultipoint: m_bInUse = true; m_pFeedback = new NewMultiPointFeedbackClass(); INewMultiPointFeedback pMPFeed = (INewMultiPointFeedback)m_pFeedback; m_pPointCollection = new MultipointClass(); pMPFeed.Start(m_pPointCollection, pPoint); break;

27、case esriGeometryType.esriGeometryPolyline: m_bInUse = true; m_pFeedback = new NewLineFeedbackClass(); pLineFeed = (INewLineFeedback)m_pFeedback; pLineFeed.Start(pPoint); break; case esriGeometryType.esriGeometryPolygon: m_bInUse = true; m_pFeedback = new NewPolygonFeedbackClass(); pPolyFeed = (INew

28、PolygonFeedback)m_pFeedback; pPolyFeed.Start(pPoint); break; if (m_pFeedback != null) m_pFeedback.Display = pActiveView.ScreenDisplay; else if (m_pFeedback is INewMultiPointFeedback) object obj = Missing.Value; m_pPointCollection.AddPoint(pPoint, ref obj, ref obj); else if (m_pFeedback is INewLineFe

29、edback) pLineFeed = (INewLineFeedback)m_pFeedback; pLineFeed.AddPoint(pPoint); else if (m_pFeedback is INewPolygonFeedback) pPolyFeed = (INewPolygonFeedback)m_pFeedback; pPolyFeed.AddPoint(pPoint); catch (Exception e) Console.WriteLine(e.Message.ToString(); / / 新建对象过程中鼠标移动方法,产生Track效果 / 在Map.MouseMo

30、ve事件中调用本方法 / / 鼠标X坐标,屏幕坐标 / 鼠标Y坐标,屏幕坐标 public void NewFeatureMouseMove(int x, int y) if (!m_bInUse) | (m_pFeedback = null) return; IActiveView pActiveView = (IActiveView)m_pMap; m_pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); m_pFeedback.MoveTo(m_pPoint); / / 新建对象过程中鼠标移动

31、方法,产生Track效果 / 在Map.MouseMove事件中调用本方法 / / 鼠标X坐标,屏幕坐标 / 鼠标Y坐标,屏幕坐标 public void NewFeatureMouseMoveBySnapPoint(IPoint dpoint) if (!m_bInUse) | (m_pFeedback = null) return; IActiveView pActiveView = (IActiveView)m_pMap; m_pFeedback.MoveTo(dpoint); / / 完成新建对象,取得绘制的对象,并添加到图层中 / 建议在Map.DblClick或Map.MouseD

32、own(Button = 2)事件中调用本方法 / public void NewFeatureEnd() IGeometry pGeom = null; IPointCollection pPointCollection; object obj = Type.Missing; try if (m_pFeedback is INewMultiPointFeedback) INewMultiPointFeedback pMPFeed = (INewMultiPointFeedback)m_pFeedback; pMPFeed.Stop(); pGeom = (IGeometry)m_pPointCollection; if (m_GeometryCollection = null) m_GeometryCollection = new PointClass() as IGeometryCollection; m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection); else if (m_pFeedback is INewLineFeedback) INewLineFeedback pLineFeed = (INewLin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论