赞
踩
地图编辑功能涉及到比较复杂的地图与鼠标的交互以及事件的响应,ArcGIS提供了强大的地图编辑的相关功能。本节我们将尝试实现一些简单的地图编辑功能,包括点、线、面要素形状的创建和移动。通过本节希望你能掌握ArcEngine实现地图编辑的机制以及常用的地图编辑的接口。
新建一个C#.Net项目,项目名称为MapEdit,添加MapControlLicenceControl、四个Button、一个ComboBox、一个Label等控件。如下图:
ArcEngine中的地图编辑使用IWorkspaceEdit接口来进行编辑状态的管理,在需要对指定的工作空间进行编辑时,首先使用IWorkspaceEdit获取该工作空间的数据,然后使用StartEditing方法开始编辑状态,StartEditOperation方法打开具体编辑的操作,编辑完成后,使用StopEditOperation方法关闭编辑操作,使用StopEditing方法关闭编辑状态,完成编辑。
在本例中,我们实现了新的点线面要素的创建和移动的功能,涉及到了比较复杂的鼠标与地图间的交互,这个功能的实现中,IDisplayFeedback是一个十分关键的接口,它具有涉及创建要素,移动要素、编辑节点等31个实现类,能够实现鼠标与地图交互中的事件的追踪,返回新的几何对象。
创建项目后注意把ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);这句代码加入到Program.cs文件中。
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Display;
定义如下成员变量。
//操作类型
string strOperator = "";
//当前地图视图
IActiveView m_activeView = null;
//当前操作图层
IFeatureLayer m_FeatureLayer = null;
//当前操作实体
IFeature m_Feature = null;
//当前点移动反馈对象
IMovePointFeedback m_MovePointFeedback = new MovePointFeedbackClass();
//当前线移动反馈对象
IMoveLineFeedback m_MoveLineFeedback = new MoveLineFeedbackClass();
//当前面移动反馈对象
IMovePolygonFeedback m_MovePolygonFeedback = new MovePolygonFeedbackClass();
加载地图文档的函数代码:
private void button1_Click(object sender, EventArgs e)
{
//加载地图文档
loadMapDocument();
//将图层名填加到下拉列表框
for (int i = 0; i < this.axMapControl1.LayerCount; i++)
{
ILayer layer = this.axMapControl1.get_Layer(i);
this.comboBox1.Items.Add(layer.Name);
}
}
//加载地图文档
private void loadMapDocument()
{
System.Windows.Forms.OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "打开地图文档";
openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
openFileDialog.ShowDialog();
string filePath = openFileDialog.FileName;
if (axMapControl1.CheckMxFile(filePath))
{
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
axMapControl1.LoadMxFile(filePath, 0, Type.Missing);
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
else
{
MessageBox.Show(filePath + "不是有效的地图文档");
}
}
combobox1添加selectedchange事件。
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.comboBox1.Text != "")
{
for (int i = 0; i < this.axMapControl1.LayerCount; i++)
{
ILayer layer = this.axMapControl1.get_Layer(i);
if (layer.Name == this.comboBox1.Text.ToString
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。