1、课 程 设 计 报 告课程名称: 地理信息系统 设计名称:Arc Engine 的二次开发 院 (系): 海洋科学与工程学院 专业班级:姓 名:学 号:指导教师:2014 年 1 月 9 日一、设计目的:(1)、实习类型:课程设计;(2)、了解 C#的软硬件环境;(3)、初步掌握该软件的基本操作技能;(4)、能够熟练的操作 C#软件,并能应用该软件简单的与 Arc Engine 进行开发(5)、掌握产品的输出设计。(6)、培养利用 GIS 方法解决实际问题的能力。二、设计主要仪器设备,器材,药品,软件等(1)软件准备:Visual Studio2010(2)硬件准备:PC 机 512 内存,1
2、28 显卡(最低)(3)资料准备:Arc Engine 控件、TangGu 等 SHP 文件三、设计原理和内容:(1)设计题目:Arc Engine 的二次开发(2)具体要求:应用 C#软件与 Arc Engine 控件进行结合,实现 Arc Engine 的二次开发。(3)ArcGIS Engine 开发简介ArcGIS 是一组集成家庭式的 GIS 软件产品,可在单项工程、工作组以及企业级项目中用于发布完善的、可升级的 GIS 系统。它是基于一个可共享的 GIS 组件一 Arc ohjects 的公用库来构建的。Arcobjects 是基于 Microsoft COM 技术所构建的一系列 C
3、OM 组件产品,不是为最终用户而是专门为开发人员提供的二次开发软件,通过 Arcobjects ,用户可以非常方便地开发出功能强大的 GIS 应用系统。但它不是一个独立的应用产品,不能脱离ArcGIS 平台,只有在购买 ArcGIS 产品后,才能利用其提供的组件对象进行应用开发。Arc Engine 是一组完备的并且打包的嵌人式 GIS 组件库和工具库,开发人员可用来创建新的或扩展已有的桌面应用程序。使用 ArcGIS Engine ,开发人员可以将 GIS 功能嵌入到已有的应用软件中,或嵌人到商业生产应用软件中,还可以创建集中式自定义应用软件,并将其发送给机构内的多个用户。ArcGIS En
4、gine 由两个产品组成:构建软件所用的开发工具包于以及使已完成的应用程序能够运行的可再发布的 Runtime (运行时环境)。AreGIS Engine 开发工具包是一个基于组件的软件开发产品,可用于构建自定义 GIS 和制图应用软件。ArcGIS Engine Runtime 是一个使终端用户软件能够运行的核心 Arcobjects 组件产品,并且将被安装在每一台运行 ArcGIS Engine 应用程序的计算机上。ArcGIs Engine 开发包包括三个关键部分:控件是 ArcGIS 用户界面的组成部分,包括地图控件和框架控件,地图控件提供了可视化的组件允许开发者对数据进行渲染、交互、
5、分析等,比如地图控件:MapControl 、Page Layout Control 和 scencontrol ; 框架控件 ToolbarControl 和 TOCControl 在平常 GIS 功能中大部分都与地图控件打交道,可以把地图控件与框架控件进行关联,能快速直接反映地图控件中图层的变化及可见性。工具条是 GIS 工具的集合,在应用程序中用它来和地图及地理信息交互。工具包括平移、缩放、点击查询和与地图交互的各种选择工具。工具在应用界面上用工具条的方式展现。通过调用一套丰富的常规的工具和工具条,建立定制应用的过程被简化了。开发者可以很容易地将选择的工具拖放到定制应用中或创建自己定制的
6、工具来实现与地图的交互。对象库是可编程 Arcobjects 组件的集合,包括几何图形到制图、 GIS 数据源和 geodatase 等一系列库。在 windows , UNIX 和 Linux、平台的开发环境下使用这些库,程序员可以开发出从低级到高级的各种定制的应用。(4)C#的简要介绍C#(全称 C sharp)是一种简单、功能强大、类型安全的面向对象类型的语言,它在许多方面都得到了创新,它在保持 C 语言风格的表现力和雅致特征的同时,实现了应用程序的快速开发。1998 年,第一个 C#语言版本诞生,到了 2000 年,国际化标准组织为该语言制定了一个由微软公司出台的新标准,最终在 200
7、1 年,C#语言得以正式发布。C#语言建立在.NET Framework 环境之上,是一门面向对象的语言,它从 C 语言和C+语言演化而来,并且结合了其他语言的许多优点,使得这门语言的易用性得到了极大的提高。作为一门典型的面向对象的语言,C#提供了面向对象组件的支持。这种组件通过属性、方法和事件来提供一种编程模型。此外,C#语言还提供了关于组件的声明信息的属性,同时,还编入了自己的相关文档。所有以上这些特点,使得 C#语言成为一种面向对象的强势语言,使其成为创建和使用软件组件的首选语言。C#语言主要有生成中间代码、垃圾回收机制等几个特点,这些特点是的 C#语言能够开发出经久耐用的应用程序。C#
8、 的几大技术特点如下。 生成中间代码:使用 C#语言开发的程序,在生成机器代码的过程中,首先会生成汇编代码,只能当它们运行的时候,才会最终生成本地计算机上的可执行代码,这样便使得该语言编写程序的安全性得到了极大的提高。 垃圾回收机制:可以释放不再使用的对象所占用的内存。 在命名空间中声明相关类:当使用 C#语言创建一个应用程序的时候,会在一个已经定义好的命名空间创建一个或者多个类,或者在这个命名空间定义某些结构体或者变量,以便提供给其他的命名空间进行引用,这样便形成了一种模块化结构,从而提高了操作效率。 异常处理机制:如果程序出现错误,C# 提供了异常处理机制,这使得进行错误检测和恢复变得非常
9、容易。 数据类型丰富:C# 语言拥有 bool 、ubyte、byte、short、ushort、int、uint、long、ulong float、double、decimal 等丰富的数据类型,众多的数据类型使其处理数据变得得心应手。 存在两个基本类可供调用:在 C# 语言中,Object 类是所有其他类的基类。而string 类和 object 类类似,也属于其中之一,它们都属于 C# 语言。这种语言处理机制使得所有类型都共享一组通用操作,而且所欲类型的值都可以以相同的方式进行存储,转换等操作,从而大大提高了工作效率。四、设计步骤(一)开发功能及开发人员功能:1、文件:新建、打开、保存、
10、另存为、添加数据、退出2、视图:数据视图、布局视图3、编辑:剪切、复制、粘贴、删除、撤销、重做4、工具:常用工具、地图导航工具栏、绘图工具5、选择:进行选择、全部选择、反向选择、清除选择、缩放已选范围6、栅格处理:卷积计算、栅格计算、栅格转矢量、矢量转栅格7、表面分析:等高线、坡度8、空间插值:反距离权重、克里金9、空间查询:按属性查询、按位置查询10、地图输出:导出 PDF、导出 EMF、导出 JPG、导出 PNG、导出 TIF分组人员具体开发功能(集成人员:张人愉):张人愉:文件、视图、栅格处理、空间插值周礼英:编辑、表面分析刘 雪:工具、地图输出蓝才鑫:选择、空间查询(二)步骤及效果图1
11、、整体框架鼠标右击功能图:1)打开属性表:2)标注:3)符号选择器:4)识别:5)创建书签:1、文件:新建、打开、保存、另存为、添加数据、退出新建代码:/定义打开文件对话框OpenFileDialog OpenFileDlg = new OpenFileDialog();/定义保存文件对话框SaveFileDialog SaveFileDlg = new SaveFileDialog();OpenFileDlg.Filter = “地图文档文件(*.mxd)|*.mxd“;SaveFileDlg.Filter = “地图文档文件(*.mxd)|*.mxd“;string strDocFileN
12、 = string.Empty;pMapDocument = new MapDocumentClass();SaveFileDlg.Title = “输入需要新建的地图文档的名称“;SaveFileDlg.ShowDialog();strDocFileN = SaveFileDlg.FileName;if (strDocFileN = string.Empty)return;pMapDocument.New(strDocFileN);pMapDocument.Open(strDocFileN, “);axMapControl1.Map = pMapDocument.get_Map(0);文件打
13、开代码: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);文件保存代码:/判断文档是否为只读文档if (pMapDocument.g
14、et_IsReadOnly(pMapDocument.DocumentFilename) = true)MessageBox.Show(“此文档为只读文档!“, “ 信息提示“);return;/用相对路径保存地图文档pMapDocument.Save(pMapDocument.UsesRelativePaths, true);MessageBox.Show(“保存成功!“, “ 信息提示 “);文件另存为代码:/execute SaveAs Document commandICommand command = new ControlsSaveAsDocCommandClass();comma
15、nd.OnCreate(m_mapControl.Object);command.OnClick();添加数据代码:ICommand pCommand;pCommand = new ESRI.ArcGIS.Controls.ControlsAddDataCommandClass();pCommand.OnCreate(axMapControl1.Object);pCommand.OnClick();退出代码:Application.Exit();2、视图:数据视图、布局视图数据视图布局视图3、编辑:剪切、复制、粘贴、删除、撤销、重做编辑功能中的六种操作的代码相似,以剪切代码为例剪切代码:ICo
16、mmand pCommand;pCommand = new ESRI.ArcGIS.Controls.ControlsEditingCutCommandClass();pCommand.OnCreate(axMapControl1.Object);pCommand.OnClick();4、工具:常用工具、地图导航工具栏、绘图工具常用工具栏:地图导航工具栏:5、选择:进行选择、全部选择、反向选择、清楚选择、缩放已选范围绘图工具:进行选择代码:ICommand pCommand;pCommand = new ESRI.ArcGIS.Controls.ControlsSelectFeaturesTo
17、olClass();if (tabControl1.SelectedTab = tabPage1)pCommand.OnCreate(axMapControl1.Object);axMapControl1.CurrentTool = pCommand as ESRI.ArcGIS.SystemUI.ITool;全部选择代码:ICommand pCommand;pCommand = new ESRI.ArcGIS.Controls.ControlsSelectAllCommandClass();pCommand.OnCreate(axMapControl1.Object);pCommand.On
18、Click();缩放到已选范围代码:ICommand pCommand;pCommand= new ESRI.ArcGIS.Controls.ControlsZoomToSelectedCommandClass();pCommand.OnCreate(axMapControl1.Object);pCommand.OnClick();6、栅格处理:卷积计算、栅格计算、栅格转矢量、矢量转栅格卷积计算:卷积计算代码:private void 卷积计算 ToolStripMenuItem_Click(object sender, EventArgs e)IRasterLayer pRasterlaye
19、r = axMapControl1.Map.get_Layer(0) as IRasterLayer;IRaster pRaster = pRasterlayer.Raster;IRasterLayer pRasterTempLayer = new RasterLayerClass();pRasterTempLayer.CreateFromDataset(GetConvo(pRaster, “C:TEMPConvolution1.afr“);axMapControl1.AddLayer(pRasterTempLayer as IRasterLayer);IRasterDataset GetCo
20、nvo(IRaster _pRaster, string _pPath)/函数数据集对象IFunctionRasterDataset pFunctionRasterDataset = new FunctionRasterDataset();IRasterFunction pRasterFunction = new ConvolutionFunction();/卷积运算参数IConvolutionFunctionArguments pRasterFunctionArguments = (IConvolutionFunctionArguments)new ConvolutionFunctionAr
21、guments();pRasterFunctionArguments.Type = esriRasterFilterTypeEnum.esriRasterFilterLaplacian5x5;pRasterFunctionArguments.Raster = _pRaster;/函数数据集名称对象,定义了结果的保存位置后缀名为 .afrIFunctionRasterDatasetName pFunctionRasterDatasetName = (IFunctionRasterDatasetName)new FunctionRasterDatasetName();pFunctionRaster
22、DatasetName.FullName = _pPath;pFunctionRasterDataset.FullName = (IName)pFunctionRasterDatasetName;/计算pFunctionRasterDataset.Init(pRasterFunction, pRasterFunctionArguments);/保存为永久的,这样我们就可以在磁盘上看到这个文件ITemporaryDataset pTemp = pFunctionRasterDataset as ITemporaryDataset;pTemp.MakePermanent();return pFun
23、ctionRasterDataset as IRasterDataset;栅格计算:栅格计算代码:WindowsApplication1.Raster_Calculatornewform = new WindowsApplication1.Raster_Calculator();newform.pMap = axMapControl1.Map;newform.Show();newform.Visible = false;DialogResult result = newform.ShowDialog();if (result = DialogResult.Cancel)return;newfo
24、rm.pCreatRalyr.Name = “Calculation“;axMapControl1.AddLayer(newform.pCreatRalyr);axMapControl1.Refresh();axTOCControl1.ActiveView.ContentsChanged();axTOCControl1.Update();axTOCControl1.ActiveView.Refresh();栅格转矢量:部分代码:WindowsApplication1.RasterToFeatures pRF = new WindowsApplication1.RasterToFeatures(
25、);pRF.pMap = axMapControl1.Map;pRF.ShowDialog();if (pRF.flag = false)return;IFeatureClass pFeatureClass = pRF.pGeoDataset as IFeatureClass;IFeatureLayer pFeatureLayer = new FeatureLayerClass();pFeatureLayer.FeatureClass = pFeatureClass;pFeatureLayer.Name = pRF.FeatureName;axMapControl1.AddLayer(pFea
26、tureLayer);axMapControl1.Refresh();axTOCControl1.ActiveView.ContentsChanged();axTOCControl1.Update();axTOCControl1.ActiveView.Refresh();矢量转栅格部分代码:WindowsApplication1.FeaturesToRaster pFR = new WindowsApplication1.FeaturesToRaster();pFR.pMap = axMapControl1.Map;pFR.ShowDialog();if (pFR.flag = false)r
27、eturn;IRasterLayer pRasterLayer = new RasterLayerClass();IRasterDataset rasterDataset = pFR.pRasterDataset;pRasterLayer.CreateFromDataset(rasterDataset);pRasterLayer.Name = pFR.RasterName;axMapControl1.AddLayer(pRasterLayer);axMapControl1.Refresh();axTOCControl1.ActiveView.ContentsChanged();axTOCCon
28、trol1.Update();axTOCControl1.ActiveView.Refresh();7、表面分析:等高线、坡度等高线:部分代码:WindowsApplication1.Contour contour = new WindowsApplication1.Contour();contour.pMap = axMapControl1.Map;contour.Show();contour.Visible = false;DialogResult result = contour.ShowDialog();if (result = DialogResult.Cancel)return;I
29、Layer pLayer = (ILayer)axMapControl1.Map.get_Layer(contour.LayerIndex);IRasterLayer pRasterLayer = (IRasterLayer)pLayer;IRaster pIRaster = pRasterLayer.Raster;ISurfaceOp pSurfaceOp = new RasterSurfaceOpClass();IGeoDataset pGeoDataset;object bContour = BContour;pGeoDataset = pSurfaceOp.Contour(IGeoDa
30、taset)pIRaster, CInternal, ref bContour);IFeatureLayer pFeatureLayer = new FeatureLayerClass();IFeatureClass pFeatureClass;pFeatureClass = (IFeatureClass)pGeoDataset;pFeatureLayer.Name = “等高线“;pFeatureLayer.FeatureClass = pFeatureClass;axMapControl1.Map.AddLayer(pFeatureLayer);axMapControl1.ActiveVi
31、ew.Refresh();axMapControl1.ActiveView.Refresh();axTOCControl1.ActiveView.ContentsChanged();axTOCControl1.Update();axTOCControl1.ActiveView.Refresh();坡度:部分代码:WindowsApplication1.Slope pSlope = new WindowsApplication1.Slope();pSlope.pMap = axMapControl1.Map;pSlope.Show();pSlope.Visible = false;DialogR
32、esult result = pSlope.ShowDialog();if (result = DialogResult.Cancel)return;ILayer pLayer = (ILayer)axMapControl1.Map.get_Layer(pSlope.LayerIndex);IRasterLayer pRasterLayer = (IRasterLayer)pLayer;IRaster pIRaster = pRasterLayer.Raster;ISurfaceOp pSurfaceOp = new RasterSurfaceOpClass();IGeoDataset pGe
33、oDataset;object zFactor = ZFactor;/if (flag = 1)pGeoDataset = pSurfaceOp.Slope(IGeoDataset)pIRaster, ESRI.ArcGIS.GeoAnalyst.esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, ref zFactor);if (flags = 2)pGeoDataset = pSurfaceOp.Slope(IGeoDataset)pIRaster, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSl
34、opePercentrise, ref zFactor);IRasterLayer pRasterLayer1 = new RasterLayer();IRaster praster = new Raster();praster = (IRaster)pGeoDataset;pRasterLayer1.CreateFromRaster(praster);pRasterLayer1.Name = “生成坡度 Raster“;axMapControl1.Map.AddLayer(pRasterLayer1);axMapControl1.ActiveView.Refresh();axMapContr
35、ol1.ActiveView.Refresh();axTOCControl1.ActiveView.ContentsChanged();axTOCControl1.Update();axTOCControl1.ActiveView.Refresh();8、空间插值:反距离权重、克里金反距离权重:部分代码:WindowsApplication1.IDW pDistance = new WindowsApplication1.IDW();pDistance.Show();pDistance.Visible = false;pDistance.pMap = axMapControl1.Map;Dia
36、logResult result = pDistance.ShowDialog();if (result = DialogResult.Cancel)return;IFeatureLayer pFeatureLayer;IFeatureClass pFeatureClass;pFeatureLayer = axMapControl1.Map.get_Layer(pDistance.layerIndex) as IFeatureLayer;pFeatureClass = pFeatureLayer.FeatureClass;IRasterLayer pRasterLayer1 = pDistan
37、ce.pRasterLayer;pRasterLayer1.Name = “IDW“;ColorRampRaster(pRasterLayer1, 9);axMapControl1.AddLayer(pRasterLayer1);axMapControl1.ActiveView.Refresh();axTOCControl1.ActiveView.ContentsChanged();axTOCControl1.Update();axTOCControl1.ActiveView.Refresh();克里金插值:部分代码:WindowsApplication1.Kriging pKriging =
38、 new WindowsApplication1.Kriging();pKriging.Show();pKriging.Visible = false;pKriging.pMap = axMapControl1.Map;DialogResult result = pKriging.ShowDialog();if (result = DialogResult.Cancel)return;ColorRampRaster(pKriging.pRasterLayer, 9);axMapControl1.AddLayer(pKriging.pRasterLayer);axMapControl1.Acti
39、veView.Refresh();axTOCControl1.ActiveView.ContentsChanged();axTOCControl1.Update();axTOCControl1.ActiveView.Refresh();9、空间查询:按属性查询、按位置查询按属性查询:按属性查询部分代码:private void AddAllLayerstoComboBox(ComboBox combox)trycombox.Items.Clear();int pLayerCount = MainAxMapControl.LayerCount;if (pLayerCount 0)combox.E
40、nabled = true;/下拉菜单可用checkBoxShowVectorOnly.Enabled = true;/复选框可用for (int i = 0; i “;private void buttonBig_Click(object sender, EventArgs e)textBoxWhereClause.SelectedText = “ “;private void buttonBigEqual_Click(object sender, EventArgs e)textBoxWhereClause.SelectedText = “ = “;private void buttonS
41、mall_Click(object sender, EventArgs e)textBoxWhereClause.SelectedText = “ “;private void buttonSmallEqual_Click(object sender, EventArgs e)textBoxWhereClause.SelectedText = “ = “;private void buttonChars_Click(object sender, EventArgs e) textBoxWhereClause.SelectedText = “%“;private void buttonChar_
42、Click(object sender, EventArgs e)textBoxWhereClause.SelectedText = “_“;private void buttonLike_Click(object sender, EventArgs e)textBoxWhereClause.SelectedText = “ Like “;private void buttonAnd_Click(object sender, EventArgs e)textBoxWhereClause.SelectedText = “ And “;private void buttonOr_Click(obj
43、ect sender, EventArgs e)textBoxWhereClause.SelectedText = “ Or “;private void buttonNot_Click(object sender, EventArgs e)textBoxWhereClause.SelectedText = “ Not “;private void buttonIs_Click(object sender, EventArgs e)textBoxWhereClause.SelectedText = “ Is “;private void buttonBrace_Click(object sen
44、der, EventArgs e)textBoxWhereClause.SelectedText = “( )“;/让输入的位置恰好处在()里面,就同 arcmap 的效果一样textBoxWhereClause.SelectionStart = textBoxWhereClause.Text.Length - 2;#endregionprivate void comboBoxMethod_SelectedIndexChanged(object sender, EventArgs e)switch (comboBoxMethod.SelectedIndex)case 0: selectmeth
45、od = esriSelectionResultEnum.esriSelectionResultNew; break;case 1: selectmethod = esriSelectionResultEnum.esriSelectionResultAdd; break;case 2: selectmethod = esriSelectionResultEnum.esriSelectionResultSubtract; break;case 3: selectmethod = esriSelectionResultEnum.esriSelectionResultAnd; break;priva
46、te void buttonApply_Click(object sender, EventArgs e)if (textBoxWhereClause.Text = “)MessageBox.Show(“请生成查询语句!“);return;this.WindowState = FormWindowState.Minimized;/通过位置查询窗口最小化frmPromptQuerying frmPrompt = new frmPromptQuerying();frmPrompt.Show();System.Windows.Forms.Application.DoEvents();/转让控制权,没
47、有这一句的话提示窗口不能正常显示PerformAttributeSelect();frmPrompt.Dispose();this.WindowState = FormWindowState.Normal;private void buttonOk_Click(object sender, EventArgs e)this.WindowState = FormWindowState.Minimized;/通过位置查询窗口最小化frmPromptQuerying frmPrompt = new frmPromptQuerying();frmPrompt.Show();System.Windows
48、.Forms.Application.DoEvents();/转让控制权,没有这一句的话提示窗口不能正常显示PerformAttributeSelect();frmPrompt.Dispose();this.Dispose();pMainform.frmAttriQueryisOpen = false;/当窗口关闭时,此变量为 false 告知系统当前没有打开的属性查询窗口private void buttonCancel_Click(object sender, EventArgs e)this.Dispose();pMainform.frmAttriQueryisOpen = false;/当窗口关闭时,此变量为 false 告知系统当前没有打开的属性查询窗口private void buttonClear_Click(object sender, EventArgs e)textBoxWhereClause.Clear();private void frmAttriQuery_FormClosed(object sender, FormClosedEventArgs e)pMainform.frmAttriQueryisOpen = false;按位置查询: