ImageVerifierCode 换一换
格式:DOCX , 页数:106 ,大小:2.04MB ,
资源ID:30403952      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/30403952.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(ArcGISEngine92+C#实例开发详细教程.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

ArcGISEngine92+C#实例开发详细教程.docx

1、ArcGISEngine92+C#实例开发详细教程第一讲 桌面GIS应用程序框架的建立本讲主要是使用MapControl、PageLayoutControl、ToolbarControl、TOCControl四个控件建立起基本的桌面GIS应用程序框架。最终成果预览如下: 1、新建项目启动VS2005,选择“文件|新建|项目”,在项目类型中选择Visual C#,再选择Windows应用程序模板,输入名称“3sdnMap”,点击确定。 在解决方案管理器中将“Form1.cs”重命名为“3sdnMap.cs”,在设计视图中,选中窗体,将其属性中的“Text”改为“3sdnMap”。2、添加控件选择

2、工具箱中的“菜单和工具栏|MenuStrip”,将其拖入窗体。选择工具箱中的“ArcGIS Windows Forms”节,将“ToolbarControl”控件拖入窗体,并将其属性中的Dock设置为Top。此时的top为除去MenuStrip的部分选择工具箱中的“菜单和工具栏|StatusStrip”,将其拖入到窗体。选择工具箱中的“容器|SplitContainer”容器拖入窗体,并将其属性中的Dock设置为Fill。变为两部分标签将TabControl控件拖入Panel1,将Alignment属性设置为Bottom,Dock属性设置为Fill。点击TabPages属性右边的按钮,弹出Ta

3、bPage集合编辑器,将tabPage1的Name设置为tabPageLayer,Text设置为图层,将tabPage2的Name设置为tabPageProperty,Text设置为属性。如下所示。 选择“图层”选项卡,拖入TOCControl控件,设置Dock属性为Fill。选择“属性”选项卡,拖入DataGridView控件,设置Dock属性为Fill。后面有修改(第二章)拖入TabControl控件到Panel2,设置Dock属性为Fill。并上述类似的方法,将两个选项卡的Name和Text分别设置为:(tabPageMap、地图),(tabPageLayout,制版)。选择“地图”选项

4、卡,拖入MapControl控件,设置Dock属性为Fill。选择“制版”选项卡,拖入PageLayoutControl控件,设置Dock属性为Fill。最后将LicenseControl控件拖入到窗体的任意地方。按F5编译运行,可以看到刚才布局好的程序界面了。3、控件绑定通过以上步骤添加的控件还只是单独存在,而我们的程序需要各控件间协同工作,因此要进行控件绑定。分别右击ToolbarControl、TOCControl控件,将Buddy设置为axMapControl1,如下图所示。 这样,工具条和图层控件就与地图控件关联了。4、添加工具此时,工具条中还没有任何工具,添加的方法也很简单。右击T

5、oolbarControl,选择“属性|Items”,点击Add,选择Commands选项卡中的Generic,双击Open、SaveAs、Redo、Undo即可将相应工具添加到工具条。 常见的工具有:Map Navigation中的导航工具,Map Inquiry中的查询工具,Feature Selection中的选择工具,你可以根据需要酌情添加工具。5、编译运行按F5即可编译运行程序,至此桌面GIS应用程序框架基本框架已经搭建好了,你可以通过工具条的工具打开地图文档,浏览地图了,效果如开篇所示。第二讲 菜单的添加及其实现在上一讲中,我们实现了应用程序基本框架,其中有个小错误,在此先跟大家说

6、明下。在“属性”选项卡中,我们当时添加的是 DataGridView 控件,这个控件是用来显示数据表的,而专门用于属性的查询和设置的控件是 PropertyGrid 控件。因此请你删除“属性”选项卡中的 DataGridView 控件,再把位于“工具箱 | 所有 Windows 窗体 |PropertyGrid ”(如果没有,右击选择“选择项”以添加此控件)控件拖到该选项卡。 在这一讲中,主要讲解菜单的添加和实现。 1、 添加菜单 在设计视图中,单击菜单栏,会出现“请在此处键入”的提示,单击提示就可以键入菜单名称,如“文件”,再单击“文件”,即可输入其下拉子菜单,如下所示:Tips : 每创建

7、一个菜单,请在其属性面板中设置 Name 属性,而且不要为中文,因此 Name 值将是此菜单响应函数的函数名的一部分,带中文的函数名,总是不好吧。 本讲中,我们将添加新建( New )、打开( Open )、添加数据( AddData )、保存( Save )、另存为( SaveAs )、退出( Exit )这些菜单,()内为相应的 Name 属性值。 Tips: 你可以在属性面板中的 Text 属性中,把菜单名设置为中英文形式,如“打开 O pen ”,带下划线的 O 表示此项菜单的快捷键是字母 O ,设置方法是在相应字母前加上“ & ”字符,如“打开 &Open ”。但这种快捷键只在打开此

8、下拉菜单时才有效,即当你单击“文件”菜单弹出下拉菜单时,按下字母 O 就可以定位到“打开”菜单。 还有一种在程序运行时都有效的全局快捷键,可以在属性面板中的“ ShortCutKeys ”中设置。 你还可以在属性面板中的 Image 属性中设置你喜欢的菜单图标。单击 Image 那一行右边的按钮,弹出如下菜单。选择“项目资源文件”,再单击导入就可以选择你的图标了。最终效果显示如下:注意,在解决方案面板中,选中刚才添加的所有图标,在其属性面板中将生成操作设置为“嵌入的资源”,这一点很重要! 2、 实现相关菜单 首先定义指针(写在 public partial class Form1 : Form

9、 下面即可): private ESRI.ArcGIS.Controls.IMapControl3 m_mapControl = null;private ESRI.ArcGIS.Controls.IPageLayoutControl2 m_pageLayoutControl = null;private IMapDocument pMapDocument;若以上指针无效,请添加以下引用: using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Di

10、splay; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.SystemUI; 在设计视图中的属性面板中,选择 Form1 ,即主窗体,单击事件按钮(闪电形状的那个按钮),打到“ Load ”事件并双击,添加此事件。 在 Form1_Load 函数中初始化这些指针: / 取得 MapControl 和 PageLayoutControl 的引用 m_mapControl = (IMapControl3)this.axMapControl1.Object;m_pageLayoutControl = (IPageLayoutControl2)this.

11、axPageLayoutControl1.Object; 依次双击每个菜单项,添加菜单响应函数。实现代码如下: / / 新建地图命令 / / / private void New_Click(object sender, EventArgs e) / 本命令涉及到 MapControl 和 PageLayoutControl 同步问题,将在下一讲中实现 / / 打开地图文档 Mxd 命令 / / / private void Open_Click(object sender, EventArgs e) / 本命令涉及到 MapControl 和 PageLayoutControl 同步问题,将

12、在下一讲中实现 / / 添加数据命令 / / / private void AddData_Click(object sender, EventArgs e) int currentLayerCount = this.axMapControl1.LayerCount; ICommand pCommand = new ControlsAddDataCommandClass(); pCommand.OnCreate(this.axMapControl1.Object); pCommand.OnClick(); / / 保存地图文档命令 / / / private void Save_Click(o

13、bject sender, EventArgs e) / 首先确认当前地图文档是否有效 if(null!=m_pageLayoutControl.DocumentFilename&m_mapControl.CheckMxFile(m_pageLayoutControl.DocumentFilename) / 创建一个新的地图文档实例 IMapDocument mapDoc = new MapDocumentClass(); / 打开当前地图文档 mapDoc.Open(m_pageLayoutControl.DocumentFilename, string.Empty); / 用 PageLa

14、yout 中的文档替换当前文档中的 PageLayout 部分 mapDoc.ReplaceContents(IMxdContents)m_pageLayoutControl.PageLayout); / 保存地图文档 mapDoc.Save(mapDoc.UsesRelativePaths, false); mapDoc.Close(); / / 另存为地图文档命令 / / / private void SaveAs_Click(object sender, EventArgs e) 可能和后面有关,先没弄 / 调用另存为命令 ICommand command = new ControlsS

15、aveAsDocCommandClass(); command.OnCreate(m_controlsSynchronizer.ActiveControl); command.OnClick(); / / 退出程序 / / / private void Exit_Click(object sender, EventArgs e) Application.Exit(); 3、 编译运行 按 F5 编译运行程序。也许你会发现,菜单命令的实现方式都是类型的。没错,在 AE9.2 中,内置了许多常用的 Command 和 Tool ,如 ControlsAddDataCommandClass 、 Co

16、ntrolsMapZoomInToolClass 、 ControlsMapPanToolClass 等等,这些内置对象在 ESRI.ArcGIS.Controls 命名空间中,你可以对象浏览器中查看。而且这些内置对象的调用方式都类似,如下所示: / 定义 ICommand command = new ControlsSaveAsDocCommandClass(); / 创建 command.OnCreate(m_controlsSynchronizer.ActiveControl); / 调用 command.OnClick(); 第三讲 MapControl与PageLayoutContr

17、ol同步在ArcMap中,能够很方面地进行MapView和Layout View两种视图的切换,而且二者之间的数据是同步显示的。关于两种视图同步的实现方法有多种,可以使用ObjectCopy对象进行数据硬拷贝,而比较简单的方法莫过于二者共享一份地图了,这也是最常用的方法。1、新建同步类ControlsSynchronizer在解决方案面板中右击项目名,选择“添加|类”,在类别中选择“Visual C#项目项”,在模板中选择“类”,输入类名“ControlsSynchronizer.cs”,将以下代码覆盖自动生成的代码:using System;using System.Drawing;usin

18、g System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.IO;using System.Runtime.InteropServices; using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.SystemUI;namespace _sdnMap / / This class is used to synchronize a gven

19、PageLayoutControl and a MapControl. / When initialized, the user must pass the reference of these control to the class, bind / the control together by calling BindControls which in turn sets a joined Map referenced / by both control; and set all the buddy controls joined between these two controls.

20、/ When alternating between the MapControl and PageLayoutControl, you should activate the visible control / and deactivate the other by calling ActivateXXX. / This calss is limited to a situation where the controls are not simultaneously visible. / public class ControlsSynchronizer #region class memb

21、ers private IMapControl3 m_mapControl = null; private IPageLayoutControl2 m_pageLayoutControl = null; private ITool m_mapActiveTool = null; private ITool m_pageLayoutActiveTool = null; private bool m_IsMapCtrlactive = true; private ArrayList m_frameworkControls = null; #endregion #region constructor

22、 / / 默认构造函数 / public ControlsSynchronizer() /初始化ArrayList m_frameworkControls = new ArrayList(); / / 构造函数 / / / public ControlsSynchronizer(IMapControl3 mapControl, IPageLayoutControl2 pageLayoutControl) : this() /为类成员赋值 m_mapControl = mapControl; m_pageLayoutControl = pageLayoutControl; #endregion

23、#region properties / / 取得或设置MapControl / public IMapControl3 MapControl get return m_mapControl; set m_mapControl = value; / / 取得或设置PageLayoutControl / public IPageLayoutControl2 PageLayoutControl get return m_pageLayoutControl; set m_pageLayoutControl = value; / / 取得当前ActiveView的类型 / public string

24、ActiveViewType get if (m_IsMapCtrlactive) return MapControl; else return PageLayoutControl; / / 取得当前活动的Control / public object ActiveControl get if (m_mapControl = null | m_pageLayoutControl = null) throw new Exception(ControlsSynchronizer:ActiveControl:rnEither MapControl or PageLayoutControl are n

25、ot initialized!); if (m_IsMapCtrlactive) return m_mapControl.Object; else return m_pageLayoutControl.Object; #endregion #region Methods / / 激活MapControl并解除the PagleLayoutControl / public void ActivateMap() try if (m_pageLayoutControl = null | m_mapControl = null) throw new Exception(ControlsSynchron

26、izer:ActivateMap:rnEither MapControl or PageLayoutControl are not initialized!);/缓存当前PageLayout的CurrentTool if(m_pageLayoutControl.CurrentTool!=null)m_pageLayoutActiveTool= m_pageLayoutControl.CurrentTool;/解除PagleLayout m_pageLayoutControl.ActiveView.Deactivate(); /激活MapControl m_mapControl.ActiveVi

27、ew.Activate(m_mapControl.hWnd);/将之前MapControl最后使用的tool,作为活动的tool,赋给MapControl的CurrentTool if (m_mapActiveTool != null) m_mapControl.CurrentTool = m_mapActiveTool; m_IsMapCtrlactive = true;/为每一个的framework controls,设置Buddy control为MapControl this.SetBuddies(m_mapControl.Object); catch (Exception ex) t

28、hrow new Exception(string.Format(ControlsSynchronizer:ActivateMap:rn0, ex.Message); / / 激活PagleLayoutControl并减活MapCotrol / public void ActivatePageLayout() try if (m_pageLayoutControl = null | m_mapControl = null) throw new Exception(ControlsSynchronizer:ActivatePageLayout:rnEither MapControl or PageLa

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1