AE入门小程序(零基础教零基础学)(共31页).doc





《AE入门小程序(零基础教零基础学)(共31页).doc》由会员分享,可在线阅读,更多相关《AE入门小程序(零基础教零基础学)(共31页).doc(31页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上AE开发 (本人希望通过这次的学习,能过交上更多喜爱AE开发的同学,大家相互交流学习。因此创建了一个QQ群:,希望喜爱AE开发的同学踊跃加入,当然,非诚勿扰。还有,本人只是初学,依靠零基础教零基础学的方式来编写的此文,有不足之处,还请见谅!)1. AE安装(1) 、首先安装Visual Studio,版本自选。(2) 、其次安装ArcGis Engine,若已安装了ArcMap则无需安装License manager。(3) 、若之前ArcMap没有安装SDK,则还需安装SDK。(AE版本必须一致)2. 运行VS,新建项目(1) 、打开VS2010(我安装的版本),(
2、2)、文件新建项目 (3)、点击Visual C#,选择Windows窗体应用程序,项目名称以My为例,点击确定如图: 3、添加引用 为了防止在以后程序出错,因此将如何添加引用和使用哪些都归结如下:(1) 、引用的添加:右击引用添加引用,选择添加引用对话框中的.NET选项将ESRI.ArcGIS.DataSourcesFile、ESRI.ArcGIS.Carto、ESRI.ArcGIS.Geodatabase、ESRI.ArcGIS.Geometry确定添加进去即可。 (2)、该程序所需所有的usingusing System;using System.Collections.Generic;
3、using System.ComponentModel;using System.Data;using System.Drawing;using System.IO;using System.Linq;using System.Text;using System.Windows.Forms;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.DataSourcesFile;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.Geometry;using ESRI.Ar
4、cGIS.Controls;using ESRI.ArcGIS.SystemUI;4、 使用工具箱中ArcGIS Windows Forms 工具运行程序(1) 、点击工具箱中的ArcGIS Windows Forms工具栏将MapControl、TOCControl、ToolbarControl和LicenseControl工具拖入Form1窗体中如图:(2) 、点击窗体中ToolbarControl控件,选择属性中Dock,从Dock下拉式列表中选择最上方的长条。如图:(3)、同上,依次将TOCControl的Dock选择最左边长条,将MapControl控件的Dock选择为中间的正方形。
5、即窗体如下:(4)右击ToolbarControl控件,选择General选项中Buddy下拉列表中axMapControl1,在点击Items选项卡中Add,双击点击添加如图所示工具,点击确定。(同理将TOCControl选择General选项中Buddy下拉列表中axMapControl1,点击确定。)(5)、按F5运行程序会发现如图错误,需要在Program.cs中添加如下代码:ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);(6)、程序即可正常运行5、代码添加MXD(1)、选择工具箱中菜单
6、和工具栏,将其中MenuStrip拖入窗体上方,并输入“打开MXD”,如图:(2)右击“打开打开MXD”或双击,向其中输入代码,并运行。代码如下: private void 打开MXD aMXDToolStripMenuItem_Click(object sender, EventArgs e) OpenFileDialog OpenMXD = new OpenFileDialog(); OpenMXD.Title = 打开地图; OpenMXD.InitialDirectory = E:; OpenMXD.Filter = Map Documents (*.mxd)|*.mxd; if (O
7、penMXD.ShowDialog() = DialogResult.OK) string MxdPath = OpenMXD.FileName; axMapControl1.LoadMxFile(MxdPath); 运行如图:6、代码添加SHP紧接着“打开MXD”旁,添加一个“添加SHP”,同上输入代码,并运行。代码如下: string ShpFile = new string2; OpenFileDialog OpenShpFile = new OpenFileDialog(); OpenShpFile.Title = 打开Shape文件; OpenShpFile.InitialDirec
8、tory = E:; OpenShpFile.Filter = Shape文件(*.shp)|*.shp; if (OpenShpFile.ShowDialog() = DialogResult.OK) string ShapPath = OpenShpFile.FileName; /利?用?将?文?件t路径?分?成两?部?分? int Position = ShapPath.LastIndexOf(); string FilePath = ShapPath.Substring(0, Position); string ShpName = ShapPath.Substring(Position
9、 + 1); ShpFile0 = FilePath; ShpFile1 = ShpName; axMapControl1.AddShapeFile(ShpFile0, ShpFile1); 运行如图:7、鹰眼功能的实现(1)、在主窗体上在添加一个axmapcontrol控件,作为鹰眼功能的鸟瞰图。如图(2) 、点击一下axmapcontrol1控件,在属性中在点击一下雷电符号,选择并双击其中OnFullExtentUpdated事件,输入代码。代码如下: private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS
10、.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) / 得?到?新?范?围 IEnvelope pEnvelope = (IEnvelope)e.newEnvelope; IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; /在绘?制?前,?清?除yaxMapControl2中D的?任?何?图?形?元a素? pG
11、raphicsContainer.DeleteAllElements(); IRectangleElement pRectangleEle = new RectangleElementClass(); IElement pElement = pRectangleEle as IElement; pElement.Geometry = pEnvelope; /设?置?鹰?眼?图?中D的?红线?框 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.T
12、ransparency = 255; /产生?一?个?线?符?号?对?象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 3; pOutline.Color = pColor; /设?置?颜?色?属?性? pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 0; /设?置?填?充?符?号?的?属?性? IFillSymbol pFillSymbol
13、= new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle = pElement as IFillShapeElement; pFillShapeEle.Symbol = pFillSymbol; pGraphicsContainer.AddElement(IElement)pFillShapeEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriV
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- AE 入门 程序 基础 31

限制150内