gis软件设计实验报告完整版_第1页
gis软件设计实验报告完整版_第2页
gis软件设计实验报告完整版_第3页
gis软件设计实验报告完整版_第4页
gis软件设计实验报告完整版_第5页
已阅读5页,还剩55页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 地理与生物信息学院2012 / 2013 学年 第 一 学期GIS软件设计实 验 报 告 课程名称: GIS软件设计 实验名称: 小型GIS软件系统的设计与开发 班 级 学 号 B B 学 生 姓 名 冶福荣 郑正中 指 导 教 师 原立峰 日 期: 2012 年 9 月1、 软件设计题目 基于ArcGIS Engine及C#编程语言构建一个小型GIS平台系统。二、设计内容软件为一个小型的GIS平台,主要包括:空间数据存取模块、地图浏览模块、地图编辑模块、空间查询模块、空间分析模块、地图修饰模块。(1)空间数据存取模块该模块实现对地图数据的新建、加载、保存、另存和打印输出对于地图的硬拷贝输出

2、实现所见即所得效果。(2)地图浏览模块该模块主要包括地图工具、滚动条,状态条、鹰眼图、内容视图等。其中地图工具可以实现放大、缩小、中心放大、中心缩小、全景视图、漫游、要素选择和取消、空间查询等具体功能。(3)地图数据编辑模块该模块能够实现新建图层、添加图层、删除所有图层、开始编辑和结束编辑的操作。编辑可以对图层进行创建新特征、修改任务、移动特征和设置捕捉环境等操作。(4)空间查询模块该模块实现的是属性查询。(5)空间分析模块该模块可以进行缓冲区分析。3、 设计要求使用ArcGIS Engine和C#、VB.net等编程语言完成任务。4、 实现过程1. 空间数据存储模块图1. 文件菜单图2. 工

3、具栏A 新建地图1、 创建同步地图类ControlsSynchronizer2、 新建新的地图对象IMap map=new map();同时更新地图文档B 加载shapefile文件和mxd文档1、 新建打开文档对话框,设置文件类型为”(*.shp)|*.shp”2、 将对话框获得的shapefile文档的地址返回,检查文档是否存在,若存在则将文档加载,并将文档中的参数添加至featureclass和featurelayer中;若不存在,则错误提示。3、 更新mapcontrol和鹰眼中的地图。C 保存地图文档使用ESRI提供的接口函数IMapDocument类中的void Save(bool

4、 bUseRelativePaths, bool bCreateThumnbail);函数。D 另存地图文档首先需用户确认是否需要保存当前的地图文档,之后调用类ControlsSaveAsDocCommandClass(),进行地图另存为操作。E 打印地图文档图3. 打印窗体界面创建打印窗体类:PrintPageLayoutForm,将地图文档传递到窗体中预览,选择打印机、纸张大小、打印方向等,将地图打印出来。F 地图输出为图片图4地图输出为图片界面 创建地图输出窗体类:ExportMapForm,选择输出的路径、分辨率、图片尺寸、图片类型,并将地图输出为图片。2. 地图浏览模块A 地图工具实

5、现工具栏中的控件,比如加载地图文件、添加地图图层、地图显示、漫游功能、中心缩放、放大缩小等功能。分别创建GIS Basic Command类:OpenNewMapDocument、ZoomIn、ZoomOut 、FixedZoomIn、FixedZoomOut、FullExtent、GoBackToPreviousExtent、GoToNextExtent、ReDoDraw、UnDoDraw。在工具栏,将这些功能添加上,单击实现。具体代码如下:/ / 新建地图文档 / / / private void OpenNewDocument_Click(object sender, EventArgs

6、 e) ICommand command = new OpenNewMapDocument(m_controlsSynchronizer); ITool tool = command as ITool; command.OnCreate(m_mapControl.Object); command.OnClick(); / / 加载数据 / / / private void AddData_Click(object sender, EventArgs e) ICommand command = new ControlsAddDataCommandClass(); command.OnCreate

7、(axMapControl1.Object); command.OnClick(); / / 全屏命令 / / / private void FullExtent_Click(object sender, EventArgs e) ICommand command = new ControlsMapFullExtentCommandClass(); command.OnCreate(m_mapControl.Object); command.OnClick(); / / 漫游命令 / / / private void PanTool_Click(object sender, EventArgs

8、 e) ICommand command = new ControlsMapPanToolClass(); ITool tool = command as ITool; command.OnCreate(m_mapControl.Object); axMapControl1.CurrentTool = tool; axPageLayoutControl1.CurrentTool = tool; / / 撤销命令 / / / private void GoBackToPreviousExtent_Click(object sender, EventArgs e) ICommand command

9、 = new GoBackToPreviousExtent(); command.OnCreate(m_mapControl.Object); command.OnClick(); / / 前进命令 / / / private void GoToNextExtent_Click(object sender, EventArgs e) ICommand command = new GoToNextExtent(); command.OnCreate(m_mapControl.Object); command.OnClick(); / / 放大命令 / / / private void ZoomI

10、n_Click(object sender, EventArgs e) ICommand command = new ZoomIn(); command.OnCreate(m_mapControl.Object); ITool tool = command as ITool; axMapControl1.CurrentTool = tool; / / 缩小命令 / / / private void ZoomOut_Click(object sender, EventArgs e) ICommand command = new ZoomOut(); command.OnCreate(m_mapC

11、ontrol.Object); ITool tool = command as ITool; axMapControl1.CurrentTool = tool; / / 中心缩小命令 / / / private void FixedZoomIn_Click(object sender, EventArgs e) ICommand command = new FixedZoomIn(); command.OnCreate(m_mapControl.Object); command.OnClick(); / / 中心放大命令 / / / private void FixedZoomOut_Clic

12、k(object sender, EventArgs e) ICommand command = new FixedZoomOut(); command.OnCreate(m_mapControl.Object); command.OnClick(); B 状态栏状态条显示当前鼠标的坐标位置,当前比例尺,还有控件名称以及目前地图的编辑状态。坐标显示的源代码如下:/ / MapControl鼠标移动响应函数 / / / private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent

13、 e) / 显示当前比例尺 ScaleLabel.Text = 比例尺 1: + (long)this.axMapControl1.MapScale).ToString(); / 显示当前坐标 CoordinateLabel.Text = 当前坐标 X = + e.mapX.ToString() + Y = + e.mapY.ToString() + + this.axMapControl1.MapUnits.ToString().Substring(4); C 鹰眼图鹰眼和主地图的互动,主要体现在两个方面:一是主地图的地图改变了,则鹰眼里的矩形框要移动到对应的位置,以指示当前地图在整个地图中

14、的位置;二是鹰眼的矩形框移动了,则主地图中显示的地图要移动到相应的位置。在主地图的OnAfterDrawMapControl事件中,根据当前地图的大小,改变鹰眼中矩形框的大小。鹰眼实现过程:1、创建函数,当主地图中的地图文档被替换时,将主地图中的图层拷贝并更新到鹰眼地图中的文档。图层拷贝函数如下:/ / 图层拷贝函数 / / / private ILayer LayerClone(ILayer pLayer) IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = (pLayer a

15、s IFeatureLayer).FeatureClass; pFeatureLayer.Name = pLayer.Name; pFeatureLayer.DisplayField = (pLayer as IFeatureLayer).DisplayField; pFeatureLayer.MaximumScale = pLayer.MaximumScale; pFeatureLayer.MinimumScale = pLayer.MinimumScale; (pFeatureLayer as IGeoFeatureLayer).Renderer = (pLayer as IGeoFeat

16、ureLayer).Renderer; (pFeatureLayer as IGeoFeatureLayer).AnnotationProperties = (pLayer as IGeoFeatureLayer).AnnotationProperties; (pFeatureLayer as IGeoFeatureLayer).DisplayAnnotation = (pLayer as IGeoFeatureLayer).DisplayAnnotation; #region 清除鹰眼中的标注 IAnnotateLayerPropertiesCollection pAnnotateLayer

17、PropertiesCollection = (pFeatureLayer as IGeoFeatureLayer).AnnotationProperties; if (pAnnotateLayerPropertiesCollection.Count 0) pAnnotateLayerPropertiesCollection.Clear(); #endregion return pFeatureLayer as ILayer;图层拷贝函数主要避免在加载具有文本标记的地图文档时因地图文档共用时的错误,通过图层拷贝,并清楚鹰眼图层中的标注,即可避免这个问题。2、鼠标事件的响应鼠标事件主要有鼠标的移

18、动、单击。当鼠标单机并移动时,绘制鹰眼框,鼠标的移动与主地图控件的地图进行互动。3. 地图数据编辑模块A 添加图层添加图层代码如下:/ / 加载shapefile数据命令 / / / private void LoadShapFileToolStripMenuItem_Click(object sender, EventArgs e) AddShapefile(); /添加Shapefile文件函数 public void AddShapefile() ESRI.ArcGIS.Carto.IActiveView activeView = axMapControl1.ActiveView; ES

19、RI.ArcGIS.Carto.IActiveView activeView1 = axMapControl2.ActiveView; if (activeView = null) return; if (activeView1 = null) return; System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.Filter = Shapefiles (*.shp)|*.shp; if (openFileDialog.Show

20、Dialog() = DialogResult.OK) string shapefileLocation = openFileDialog.FileName; string pathFile = shapefileLocation; if (shapefileLocation != ) IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFrom

21、File(System.IO.Path.GetDirectoryName(shapefileLocation), 0); IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(shapefileLocation); IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.FeatureClass = featureClass; featureLayer.Name

22、 = featureClass.AliasName; featureLayer.Visible = true; /添加到主窗口中的代码 activeView.FocusMap.AddLayer(featureLayer); activeView.Extent = activeView.FullExtent; activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); /添加到鹰眼视图窗口中的代码 activeView1.FocusMap.AddLayer(featureLayer); activeVie

23、w1.Extent = activeView1.FullExtent; activeView1.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); else MessageBox.Show(操作出错啦!); B 删除所有图层删除所有图层这个功能目前只能实现把图层隐藏,达到完全删除的功能还未实现。C 编辑栏实现地图编辑栏主要实现的是地图要素的描绘、移动、删除、修改等。实现的思路是调用ESRI提供的接口。在界面上添加两个ToolBarControl,分别在其中命名为axEditToolBar和axExtraToolbar

24、。添加命令至ToolBar中:代码如下:/ axToolbarControl1.SetBuddyControl(axMapControl1); axEditToolBar.SetBuddyControl(axMapControl1); axExtraToolbar.SetBuddyControl(axMapControl1); /set the toolbar /ExtraEditorToolbar axExtraToolbar.AddItem(esriControls.ControlsUndoCommand, 0, -1, true, 0, esriCommandStyles.esriCom

25、mandStyleIconOnly); axExtraToolbar.AddItem(esriControls.ControlsRedoCommand, 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axExtraToolbar.AddItem(esriControls.ControlsEditingCutCommand, 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axExtraToolbar.AddItem(esriControls.C

26、ontrolsEditingPasteCommand, 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axExtraToolbar.AddItem(esriControls.ControlsEditingCopyCommand, 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axExtraToolbar.AddItem(esriControls.ControlsEditingClearCommand, 0, -1, false, 0, es

27、riCommandStyles.esriCommandStyleIconOnly); /EditorToolbar axEditToolBar.AddItem(esriControls.ControlsEditingEditorMenu, 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); /command axEditToolBar.AddItem(EditorCommands.GeneralizeCmd, 0, -1, false, 0, esriCommandStyles.esriCommandStyleTextOn

28、ly); axEditToolBar.AddItem(esriControls.ControlsEditingEditTool, 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditToolBar.AddItem(esriControls.ControlsEditingSketchTool, 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditToolBar.AddItem(esriControls.ControlsEditin

29、gTargetToolControl, 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditToolBar.AddItem(esriControls.ControlsEditingTaskToolControl, 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditToolBar.AddItem(esriControls.ControlsEditingAttributeCommand, 0, -1, false, 0, esriCo

30、mmandStyles.esriCommandStyleIconOnly); axEditToolBar.AddItem(esriControls.ControlsEditingSketchPropertiesCommand, 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditToolBar.AddItem(esriControls.ControlsUndoCommand, 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);axEditTo

31、olBar.AddItem(esriControls.ControlsRedoCommand, 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);图5 编辑工具和要素编辑工具按钮实现上述两个工具栏的显示和隐藏代码如下:/ / 编辑工具栏隐藏显示命令 / / / private void EditToolStripMenuItem_Click(object sender, EventArgs e) if (axEditToolBar.Visible = false) axEditToolBar.Visible = true;

32、 else axEditToolBar.Visible = false; / / 要素编辑工具栏隐藏显示命令 / / / private void ExtraEditToolStripMenuItem_Click(object sender, EventArgs e) if (axExtraToolbar.Visible = false) axExtraToolbar.Visible = true; else axExtraToolbar.Visible = false; D 图层符号修改图6图层符号修改4. 空间查询模块A 属性查询属性查询,实现对地图要素的查询,新建一个查询窗体,根据条件进

33、行属性查询,并将查询到的要素进行闪烁和高亮显示。演示图片如下:图7实现要素的闪烁和高亮显示图8查询窗体界面B 属性查看图9属性查看窗体5. 空间分析模块A 缓冲区分析缓冲区分析实现的是对当前地图工作空间内的文档进行选定区图层的缓冲区分析,将分析产生的图层保存到指定路径。演示图片如下:图10缓冲区分析窗体6. 自定义功能A 地图输出修饰地图输出修饰主要添加了在PageLayout中添加指北针、经纬网格的添加和删除、添加图例、添加比例尺等功能。演示图片如下:图11实现地图的修饰B 工具栏的更新工具栏更新实现的是工具栏的拖动和停靠,并定制自定义控件。工具栏的拖动停靠的演示图片如下:图10工具栏停靠状

34、态图12工具栏拖动状态C 测量模块实现测量模块主要实现的是线的长度测量和面的面积测量。演示图片如下:图13 测量界面图14 线的长度测量图15 面的面积测量D 工程的部署第一步、在自己的工程项目中添加新建项目。图16第二步、选择安装和部署中的安装项目,并填写项目名称以及选择项目的存储路径。图17第三步、在应用程序文件夹下添加项目输出图18第四步、将检测到的依赖项排除图19 图20 第五步、生成图20五、GIS软件设计小结为期两周的GIS软件设计的实习结束了,这期间收获了很多,每天查阅很多的资料,将查找到的资料、代码添加到自己的工程当中,这是一个进步的过程。虽然完成的功能不是很多,但是每一个功能

35、都是自己从网站、ESRI公司提供的Demo还有老师提供的文档中的代码实现的。但是自己完成的系统中还有存在一些不足,比如说在地图输出修饰模块中,添加的比例尺、图例、指北针等要素时,不能够移动位置,没有实现属性编辑功能,系统运行速度慢,代码的健壮性差,有些地方没有进行异常抛出处理导致执行某些功能时导致异常错误等等。这些不足因素的存在说明我还是有待提高。同时经过两周的GIS软件实习,对GIS软件开发产生了浓厚的兴趣,希望能够在接下来的课程学习中能够收获到更多的知识。六、参考资料1童爱红.Visual C#.NET应用教程(第2版)(Visual C#2008版)M.北京:清华大学出版社北京交通大学出

36、版社,20112 /html/52/25952.html七、附录打印地图窗体类的源代码如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using ESRI.ArcGIS.Output;using ESRI.ArcGIS.Controls;using

37、ESRI.ArcGIS.Carto;namespace GIS public partial class PrintPageLayoutForm : Form public PrintPageLayoutForm(IHookHelper hookHelper) InitializeComponent(); axPageLayoutControl1.PageLayout = hookHelper.PageLayout; private void cmdPrint_Click(object sender, System.EventArgs e) if (axPageLayoutControl1.P

38、rinter != null) /Set mouse pointer axPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass; /Get IPrinter interface through the PageLayoutControls printer IPrinter printer = axPageLayoutControl1.Printer; /Determine whether printer papers orientation needs changing if (print

39、er.Paper.Orientation != axPageLayoutControl1.Page.Orientation) printer.Paper.Orientation = axPageLayoutControl1.Page.Orientation; /Update the display UpdatePrintingDisplay(); /Print the page range with the specified overlap axPageLayoutControl1.PrintPageLayout(Convert.ToInt16(txbStartPage.Text), Con

40、vert.ToInt16(txbEndPage.Text), Convert.ToDouble(txbOverlap.Text); /Set the mouse pointer axPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; MessageBox.Show(打印图片保存成功!, 保存, MessageBoxButtons.OK); this.Close(); private void PrintPageLayoutForm_Load(object sender, EventArgs

41、 e) /Add esriPageFormID constants to drop down cboPageSize.Items.Add(Letter - 8.5in x 11in.); cboPageSize.Items.Add(Legal - 8.5in x 14in.); cboPageSize.Items.Add(Tabloid - 11in x 17in.); cboPageSize.Items.Add(C - 17in x 22in.); cboPageSize.Items.Add(D - 22in x 34in.); cboPageSize.Items.Add(E - 34in x 44in.); cboPageSize.Items.Add(A5 - 148mm x 210mm.); cboPageSize.Items.Add(A4 - 2

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论