您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 咨询培训 > Arcengine地图编辑工具条
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Reflection;usingSystem.IO;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;usingSystem.Runtime.Serialization.Formatters.Binary;usingESRI.ArcGIS.Carto;usingESRI.ArcGIS.Display;usingESRI.ArcGIS.Geometry;usingESRI.ArcGIS.esriSystem;usingESRI.ArcGIS.DataSourcesGDB;usingESRI.ArcGIS.Geodatabase;usingESRI.ArcGIS.Controls;namespaceLGGIS.MapEdit{publicclassArcgisEditor{///summary///使用本类可以新建点、线、面///移动点、线、面///编辑线、面的节点///使用时需设置Map和CurrentLayer////summaryprivateIMapControl3m_pMapControl;privateILayerm_pCurrentLayer;privateIMapm_pMap;privateIFeaturem_pEditFeature;privateIPointm_pPoint;privateIDisplayFeedbackm_pFeedback;//privateISelectionTrackerm_pSelectionTracker;privateboolm_bInUse;privateIPointCollectionm_pPointCollection;privateISelectionm_Selection=null;privateIGeometryCollectionm_GeometryCollection=null;publicstaticIEnumFeatureSelEnumFeature=null;privateIArraym_ElementArray=newArrayClass();publicIMapControl3MapControl{get{returnm_pMapControl;}set{m_pMapControl=value;}}///summary///当前图层////summarypublicILayerCurrentLayer{get{returnm_pCurrentLayer;}set{m_pCurrentLayer=(ILayer)value;}}///summary///地图对象////summarypublicIMapMap{get{returnm_pMap;}set{m_pMap=(IMap)value;}}///summary///选中的要素////summarypublicISelectionSelection{get{returnm_Selection;}set{m_Selection=value;}}///summary///构造函数////summarypublicArcgisEditor(){}publicboolIsStartEdit(){IWorkspaceEditpWorkspaceEdit;IFeatureClasspFeatureCls;IFeatureLayerpFeatureLyr;boolpIsStart=false;for(inti=0;im_pMapControl.LayerCount;i++){pFeatureLyr=m_pMapControl.Map.get_Layer(i)asIFeatureLayer;if(pFeatureLyr==null){continue;}pFeatureCls=pFeatureLyr.FeatureClass;pWorkspaceEdit=((IDataset)pFeatureCls).WorkspaceasIWorkspaceEdit;if(pWorkspaceEdit.IsBeingEdited()==true){pIsStart=true;break;}}returnpIsStart;}publicILayergetCurrentLayer(){ILayerpLayer=CheckEditingFeatureLayer();returnpLayer;}publicILayerCheckEditingFeatureLayer(){IWorkspaceEditpWorkspaceEdit;IFeatureClasspFeatureCls;IFeatureLayerpFeatureLyr;ILayerpLayer=null;for(inti=0;im_pMapControl.LayerCount;i++){if(m_pMapControl.Map.get_Layer(i)isIFeatureLayer){pFeatureLyr=m_pMapControl.Map.get_Layer(i)asIFeatureLayer;if(pFeatureLyr==null){continue;}pFeatureCls=pFeatureLyr.FeatureClass;pWorkspaceEdit=((IDataset)pFeatureCls).WorkspaceasIWorkspaceEdit;if(pWorkspaceEdit.IsBeingEdited()==true){pLayer=pFeatureLyrasILayer;ILayerplyr=m_pMapControl.CustomPropertyasILayer;if(plyr!=null&&((IDataset)((IFeatureLayer)plyr).FeatureClass).Workspace==((IDataset)pFeatureCls).Workspace){pLayer=plyr;}break;}}}returnpLayer;}///summary///开始编辑,使工作空间处于可编辑状态///在进行图层编辑前必须调用本方法////summarypublicvoidStartEditing(){try{if(m_pCurrentLayer==null)return;if(!(m_pCurrentLayerisIGeoFeatureLayer))return;IFeatureLayerpFeatureLayer=(IFeatureLayer)m_pCurrentLayer;IDatasetpDataset=(IDataset)pFeatureLayer.FeatureClass;if(pDataset==null)return;//开始编辑,并设置Undo/Redo为可用IWorkspaceEditpWorkspaceEdit=(IWorkspaceEdit)pDataset.Workspace;if(!pWorkspaceEdit.IsBeingEdited()){pWorkspaceEdit.StartEditing(true);pWorkspaceEdit.EnableUndoRedo();}}catch(Exceptione){Console.WriteLine(e.Message.ToString());}}///summary///停止编辑,并将以前的编辑结果保存到数据文件中。////summarypublicvoidStopEditing(){boolbHasEdits=false;boolbSave=false;try{if(m_pCurrentLayer==null)return;IFeatureLayerpFeatureLayer=(IFeatureLayer)m_pCurrentLayer;if(pFeatureLayer.FeatureClass==null)return;IDatasetpDataset=(IDataset)pFeatureLayer.FeatureClass;if(pDataset==null)return;//如果数据已被修改,则提示用户是否保存IWorkspaceEditpWorkspaceEdit=(IWorkspaceEdit)pDataset.Workspace;if(pWorkspaceEdit.IsBeingEdited()){pWorkspaceEdit.HasEdits(refbHasEdits);if(bHasEdits){DialogResultresult;result=MessageBox.Show(是否保存已做的修改?,提示,MessageBoxButtons.YesNo);if(result==DialogResult.Yes){bSave=true;}}pWorkspaceEdit.StopEditing(bSave);}m_pMap.ClearSelection();IActiveViewpActiveView=(IActiveView)m_pMap;pActiveView.Refresh();}catch(Exceptione){Console.WriteLine(e.Message.ToString());}}publicboolHasEdits(){IWorkspaceEditpWorkspaceEdit;IFeatureLayerpFeatureLayer=m_pCurrentLayerasIFeatureLayer;pWorkspaceEdit=((IDataset)pFeatureLayer.FeatureClass).WorkspaceasIWorkspaceEdit;boolblHasEdits=false;pWorkspaceEdit.HasEdits(refblHasEdits);returnblHasEdits;}///summary///检查工作空间中是否有数据处于编辑状态////summary///returns是否正在编辑/returnspublicboolInEdit(){try{if(m_pCurrentLayer==null)returnfalse;IFeatureLayerpFeatureLayer=(IFeatureLayer)m_pCurrentLayer;if(pFeatureLayer.FeatureClass==null)returnfalse;IDatasetpDataset=(IDataset)pFeatureLayer.FeatureClass;if(pDataset==null)returnfalse;IWorkspaceEditpWorkspaceEdit=(IWorkspaceEdit)pDataset.Workspace;if(pWorkspaceEdit.IsBeingEdited())returntrue;returnfalse;}catch(Exceptione){Console.WriteLine(e.Message.ToString());returnfalse;}}///summary///新建对象方法///当前图层为点图层时,每调用一次就新点一个点对象///当前图层为线图层或面图层时,第一次调用开始新建对象,并添加当前点,///以后每调用一次,即向新对象中添加一个点,调用NewFeatureEnd方法完成对象创建///在Map.MouseDown事件中调用本方法////summary///paramname=x鼠标X坐标,屏幕坐标/param///paramname=y
本文标题:Arcengine地图编辑工具条
链接地址:https://www.777doc.com/doc-4338187 .html