欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

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

    • 资源ID:13430050       资源大小:2.46MB        全文页数:31页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

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

    精选优质文档-倾情为你奉上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)、文件新建项目 (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;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.ArcGIS.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选择为中间的正方形。即窗体如下:(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)、选择工具箱中菜单和工具栏,将其中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 (OpenMXD.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.InitialDirectory = "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 + 1); ShpFile0 = FilePath; ShpFile1 = ShpName; axMapControl1.AddShapeFile(ShpFile0, ShpFile1); 运行如图:7、鹰眼功能的实现(1)、在主窗体上在添加一个axmapcontrol控件,作为鹰眼功能的鸟瞰图。如图(2) 、点击一下axmapcontrol1控件,在属性中在点击一下雷电符号,选择并双击其中OnFullExtentUpdated事件,输入代码。代码如下: private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) / 得?到?新?范?围§ IEnvelope pEnvelope = (IEnvelope)e.newEnvelope; IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; /在ú绘?制?前°,?清?除yaxMapControl2中D的?任?何?图?形?元a素? pGraphicsContainer.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.Transparency = 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 = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle = pElement as IFillShapeElement; pFillShapeEle.Symbol = pFillSymbol; pGraphicsContainer.AddElement(IElement)pFillShapeEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); (3) 、同样再选择axmapcontrol1中axMapControl1_OnMapReplaced事件,输入代码。 private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e) if (axMapControl1.LayerCount > 0) axMapControl2.Map = new MapClass(); for (int i = 0; i <= axMapControl1.Map.LayerCount - 1; i+) axMapControl2.AddLayer(axMapControl1.get_Layer(i); axMapControl2.Extent = axMapControl1.Extent; axMapControl2.Refresh(); (4) 、点击一下axMapControl2控件,选择OnMouseMove和OnMouseDown事件,分别输入如下代码。 private void axMapControl2_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e) if (axMapControl2.Map.LayerCount > 0) if (e.button = 1) IPoint pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); axMapControl1.CenterAt(pPoint); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); else if (e.button = 2) IEnvelope pEnv = axMapControl2.TrackRectangle(); axMapControl1.Extent = pEnv; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); private void axMapControl2_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) if (axMapControl2.Map.LayerCount > 0) if (e.button = 1) IPoint pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); axMapControl1.CenterAt(pPoint); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); else if (e.button = 2) IEnvelope pEnv = axMapControl2.TrackRectangle(); axMapControl1.Extent = pEnv; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); (7) 、对于如图所出现的错误,需要在引用中找到各自所属的引用并右击属性,选择其中嵌入互操作类选项,把True改为False即可。如图已解决运行如下8、显示图幅范围坐标值(1)、在主窗体中添加一个statusStrip(状态栏)控件。(2)、右击statusStrip1控件,在弹出的菜单中单击选择“Edit Items”,如下图所示:(3)、在弹出的“Items Collection Editor”对话框总单击Add按钮,添加三个状态项目成员,并把“toolStripStatusLablel1“Text属性改为“当前图幅信息”,如下图所示:(4)、在主图(axMapControl1)axMapControl1_OnFullExtentUpdated事件中添加如下代码,实现当主图的图幅范围改变时,状态也相应的显示出当前图幅的信息。代码如下: IPoint l1, ur; l1 = axMapControl1.Extent.LowerLeft; ur = axMapControl1.Extent.UpperRight; toolStripStatusLabel2.Text = "(" + Convert.ToString(l1.X) + "," + Convert.ToString(l1.Y) + ")" toolStripStatusLabel3 .Text= "(" + ur.X.ToString("0.00") + "," + ur.Y.ToString("0.00") + ")"运行如下:9、显示属性表的信息(1)、在主窗体上添加一个“contextMenuStrip“(上下文)控件。右击“contextMenuStrip1“控件,选择”Edit Items“在弹出的“items collection editor“对话框中,单击Add按钮,添加一个打开属性表菜单。把text中toolStripMenuItem1改成打开属性表即可(2)、右击工程名称,在弹出的菜单中选择添加新项。在弹出的“新建项”对话框中选择“windows form”,并把“name”改为属性表。在”属性表”窗体中添加一个“dataGridView”控件,并通过点击“dataGridView”控件右上角的三角图标,为“dataGridView”添加一条属性列。(3)、将dataGridView控件的Name的dataGridView改为dtGridView。(4)、编写axTOCControl1控件右击响应事件代码,实现当在axTOCControl1控件上右击时,弹出打开属性表菜单。 首先定义一个全局变量,如下图所示:即代码为:public ILayer pLayer;其次编写axTOCControl1控件右击响应事件代码,在 axTOCControl1_OnMouseDown事件中添加代码。代码为: if (axMapControl1.LayerCount > 0) esriTOCControlItem pItem = new esriTOCControlItem(); pGlobalFeatureLayer = new FeatureLayerClass(); IBasicMap pBasicMap = new MapClass(); object pOther = new object(); object pIndex = new object(); axTOCControl1.HitTest( e.x, e.y, ref pItem, ref pBasicMap, ref pLayer, ref pOther, ref pIndex); if (e.button = 2) contextMenuStrip1.Show(axTOCControl1, e.x, e.y); 编写“打开属性表“单击事件代码,实现当单击“打开属性表“菜单时,弹出相应feature属性表,添加代码如下: private void 打开属性表ToolStripMenuItem1_Click(object sender, EventArgs e) 属性表 Ft = new 属性表(pLayer as IFeatureLayer); Ft.Show(); 在属性表窗体中定义一个全局变量pFeatureLayer,实现主窗体与属性窗体之间的值传递代码为:IFeatureLayer pFeatureLayer = null;修改属性表窗体的构造函数,实现属性表窗体的初始化代码为: public 属性表(IFeatureLayer featureLayer) InitializeComponent(); pFeatureLayer = featureLayer; Itable2Dtable(); 编写“public void Itable2Dtable()“函数,实现往”dtGridView“控件上添加相应要素的属性记录.代码为:public void Itable2Dtable() IFields pFields; pFields = pFeatureLayer.FeatureClass.Fields; dtGridView.ColumnCount = pFields.FieldCount; for (int i = 0; i < pFields.FieldCount; i+) string fldName = pFields.get_Field(i).Name; dtGridView.Columnsi.Name = fldName; dtGridView.Columnsi.ValueType = System.Type.GetType(ParseFieldType(pFields.get_Field(i).Type); IFeatureCursor pFeatureCursor; pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false); IFeature pFeature; pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) string fldValue = new stringpFields.FieldCount; for (int i = 0; i < pFields.FieldCount; i+) string fldName; fldName = pFields.get_Field(i).Name; if (fldName = pFeatureLayer.FeatureClass.ShapeFieldName) fldValuei = Convert.ToString(pFeature.Shape.GeometryType); else fldValuei = Convert.ToString(pFeature.get_Value(i); dtGridView.Rows.Add(fldValue); pFeature = pFeatureCursor.NextFeature(); 运行如下:专心-专注-专业

    注意事项

    本文(AE入门小程序(零基础教零基础学)(共31页).doc)为本站会员(飞****2)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开