|
出于学习的目的,新手第一次用arcgis engine即AE进行二次开发:arcgis engine可以开发出独立于arcgis的应用程序,里面提供了几百种类和接口用于开发工具,目前现在主流的是基于C#的二次开发,建议用这种开发语言,因为用c#开发难度还是小一点,这方面的资料也比较多,可参考。下面本人分享下个人的开发过程。
1、安装arcgis10.2desktop(此处不多说,步骤网上都有)。
2、安装VS2012(注意安装的时候要注意与arcgis10.2的兼容性,因为有的VS版本arcgis10.2是不支持的)。(具体下载地址可参考:https://www.pianshen.com/article/48421057586/)。
3、以上两个平台安装好以后,就可以进行二次开发了。首先,打开VS2012,新建->项目->选择visualC#下的Windows窗体应用程序,选择好路径和名称,点击确定。
4、要在工具箱里增加arcgis engine工具,在工具箱空白处右击->添加选项卡->命名为ESRI,在ESRI上面右击->选择项->.NET Framework插件->选择自己需添加的工具,如下图所示:一般选择axmapcontrol、axpagelayoutcontrol、axtocccontrol、axtoolbarcontrol等。
5、在左侧解决资源管理器的引用上右击->添加引用,双机:ESRI.ArcGis.CARTO\ESRI.ArcGis.DISPLAY\ESRI.ArcGis.Geometry、ESRI.ArcGis.systerm、ESRI.ArcGis.systermui、ESRI.ArcGis.utility,添加到引用上来。(此时要在添加的引用上右击->属性->嵌入互操作类型->选择FALSE,否则会出现错误提示:无法嵌入互操作类型“ESRI.ArcGIS.Carto.RectangleElementClass”。请改用适用的接口。)
6、此时就可以编程了。将工具箱中axmapcontrol拖放到form窗体中,双击form窗体的空白处,切换到代码编辑界面,就可以在Form1_Load(object sender, EventArgs e)函数中添加代码。
如:加载mxd工程的代码:(在程序的开头注意要加上using ESRI.ArcGIS.Controls;)
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 + "不是有效的地图文档");
}
7、点击运行,此时会发现有““System.Runtime.InteropServices.COMException”类型的未经处理的异常在 System.Windows.Forms.dll 中发生 ”错误提示
解决办法:菜单->项目->add arcgis liense checking,选择arcgis engine,点击确定。
最后,运行,效果如下:
|
|