收藏 分享(赏)

GIS实验报告.doc

上传人:HR专家 文档编号:11522471 上传时间:2020-05-29 格式:DOC 页数:14 大小:681KB
下载 相关 举报
GIS实验报告.doc_第1页
第1页 / 共14页
GIS实验报告.doc_第2页
第2页 / 共14页
GIS实验报告.doc_第3页
第3页 / 共14页
GIS实验报告.doc_第4页
第4页 / 共14页
GIS实验报告.doc_第5页
第5页 / 共14页
点击查看更多>>
资源描述

1、实验报告GIS应用软件开发专 业: 测绘工程 班 级: 10级测绘三班姓 名: 学 号: 指导教师: 胡 亚 撰写时间:2013年5月20日星期一目录一、程序运行演示2二、问题及解决方案6三、源程序代码7四、心得体会14一、程序运行演示1. 新建项目文件,并实现file中的基本功能,显示地图基本要素。如图1图12. 在工具栏加载按钮,按钮功能是对当前视图缩小3倍;在工具栏加载工具,工具功能在地图上标注当前日期。如图2图2按钮实现缩小3倍功能操作,如图3图33. 点击地图节点,弹出如图4,图5菜单并实现菜单中的内容:图4图54. 点击图层节点,弹出如图6菜单并需要实现菜单中的内容图65. 点击L

2、egend Class,弹出符号选择对话框,该对话框供用户按需要选择符号并进行更改。如图7图76. 打开图层属性表,用户选择某条记录,可弹出如图8,9所示的右键菜单,并实现右键菜单中的内容图8图9二、问题及解决方案问题1.VS2008与2010之间要进行格式转换,按照所导向的步骤进行,否则程序将无法正常运行,出现错误问题2.构建好基本框架后,地图文档中要素显示出现问题。此问题要添加licence控件,否则无法显示地图要素。问题3.使用Toolbar和Toc功能时无法进行操作此问题应在属性设置时建立关联功能。问题4.程序Program文件中要添加相应功能键语句,否则将无法实现功能。问题5.引用接

3、口,方法,例如ADF,要添加相应的引用,否则程序出现错误。问题6. 在实现两个自定义按钮与工具时,遇到的问题:先直接引用现有项未实现,发现缺少一些东西,后自己直接创建的Basetool和Basecommand类;在代码中报错,重新生成解决方案后顺利解决这个问题。问题7. 在实现地图和图层节点的右键功能时,遇到琐碎的问题,在这个过程中直接引用老师所给的几个类,但是报错,是因为命名空间未做修改;缺少引用,需要根据错误提示添加相应的引用三、源程序代码using System;using System.Collections.Generic;using System.ComponentModel;us

4、ing System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Runtime.InteropServices;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.ADF;using ESRI.ArcGIS.SystemUI;using ESRI.ArcGIS.

5、Display;namespace WindowsFormsApplication2 public partial class MainForm : Form #region class private members private IMapControl3 m_mapControl = null; private string m_mapDocumentName = string.Empty; #endregion IMapDocument m_MapDocument = new MapDocument(); #region class constructor private ITOCCo

6、ntrol2 m_tocControl; private IToolbarMenu m_menuMap; private IToolbarMenu m_menuLayer; private ZoomIn3XCMD1 test = new ZoomIn3XCMD1(); public MainForm() InitializeComponent(); private void newDocumentToolStripMenuItem_Click(object sender, EventArgs e) ICommand command = new CreateNewDocument(); comm

7、and.OnCreate(m_mapControl.Object); command.OnClick(); private void openDocumentToolStripMenuItem_Click(object sender, EventArgs e) openFileDialog1.Title = Save Map Document As; openFileDialog1.Filter = Map Documents (*.mxd)|*.mxd; openFileDialog1.ShowDialog(); string sFilePath = openFileDialog1.File

8、Name; if (axMapControl1.CheckMxFile(sFilePath) axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass; axMapControl1.LoadMxFile(sFilePath, 0, Type.Missing); axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; else MessageBox.Show(sFilePath + is not a valid A

9、rcMap document); return; private void MainForm_Load(object sender, EventArgs e) /get the MapControl m_mapControl = (IMapControl3)axMapControl1.Object; /disable the Save menu (since there is no document yet) this.menuSaveDoc.Enabled = false; /定义地图右键菜单,图层右键菜单 m_tocControl = (ITOCControl2)axTOCControl1

10、.Object; m_mapControl = (IMapControl3)axMapControl1.Object; /添加菜单到地图节点 m_menuMap = new ToolbarMenu(); m_menuMap.AddItem(esriControls.ControlsAdddataCommand, -1, 0, false, esriCommandStyles.esriCommandStyleTextOnly); m_menuMap.AddItem(new LayerVisibility(), 1, 1, false, esriCommandStyles.esriCommandS

11、tyleTextOnly); m_menuMap.AddItem(new LayerVisibility(), 2, 2, false, esriCommandStyles.esriCommandStyleTextOnly); /添加菜单到图层节点 m_menuLayer = new ToolbarMenu(); m_menuLayer.AddItem(new OpenAttributeTableCmd(), -1, 0, false, esriCommandStyles.esriCommandStyleIconAndText);/右键添加属性表 m_menuLayer.AddItem(new

12、 RemoveLayer(), 1, 1, false, esriCommandStyles.esriCommandStyleTextOnly); m_menuLayer.AddItem(new RemoveLayer(), 1, 2, true, esriCommandStyles.esriCommandStyleTextOnly); m_menuLayer.AddItem(new ScaleThresholds(), 2, 3, false, esriCommandStyles.esriCommandStyleTextOnly); m_menuLayer.AddItem(new Scale

13、Thresholds(), 3, 4, false, esriCommandStyles.esriCommandStyleTextOnly); m_menuLayer.AddItem(new LayerSelectable(), 1, 5, true, esriCommandStyles.esriCommandStyleTextOnly); m_menuLayer.AddItem(new LayerSelectable(), 2, 6, false, esriCommandStyles.esriCommandStyleTextOnly); m_menuLayer.AddItem(new Zoo

14、mToLayer(), -1, 7, true, esriCommandStyles.esriCommandStyleTextOnly); /Set the hook of each menu m_menuLayer.SetHook(m_mapControl); m_menuMap.SetHook(m_mapControl); axToolbarControl1.AddItem(test, -1, -1, true, 0, esriCommandStyles.esriCommandStyleIconAndText); axToolbarControl1.AddItem(new AddDateT

15、ool(), -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText); private void saveDocumentToolStripMenuItem_Click(object sender, EventArgs e) /execute Save Document command if (m_mapControl.CheckMxFile(m_mapDocumentName) /create a new instance of a MapDocument IMapDocument mapDoc = new MapDo

16、cument(); mapDoc.Open(m_mapDocumentName, string.Empty); /Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_mapDocumentName) MessageBox.Show(Map document is read only!); mapDoc.Close(); return; /Replace its contents with the current map mapDoc.ReplaceContents(IMxdContents)m_m

17、apControl.Map); /save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); /close the MapDocument mapDoc.Close(); #endregion private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) /execute SaveAs Document command ICommand command = new ControlsSaveAsDo

18、cCommand(); command.OnCreate(m_mapControl); command.OnClick(); private void exitToolStripMenuItem_Click(object sender, EventArgs e) Application.Exit(); private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) statusBarXY.Text = string.Format(0, 1 2, e.mapX.ToStrin

19、g(#.#), e.mapY.ToString(#.#), axMapControl1.MapUnits.ToString().Substring(4); private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e) test.m_activeView = this.axMapControl1.ActiveView;/添加两个工具时添加 /get the current document name from the MapControl m_mapDocument

20、Name = m_mapControl.DocumentFilename; /if there is no MapDocument, diable the Save menu and clear the statusbar if (m_mapDocumentName = string.Empty) menuSaveDoc.Enabled = false; statusBarXY.Text = string.Empty; else /enable the Save manu and write the doc name to the statusbar menuSaveDoc.Enabled =

21、 true; statusBarXY.Text = Path.GetFileName(m_mapDocumentName); private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) if (e.button = 1) /IBasicMap map = new Map(); IMap Map = new Map(); IBasicMap map = (IBasicMap)Map; ILayer layer = new FeatureLayer(); object oth

22、er = new object(); object index = new object(); esriTOCControlItem item = new esriTOCControlItem(); /Determine what kind of item has been clicked on axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); /QI to IFeatureLayer and IGeoFeatuerLayer interface if (layer = nu

23、ll) return; IFeatureLayer featureLayer = layer as IFeatureLayer; if (featureLayer = null) return; IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer; ILegendClass legendClass = new LegendClass(); ISymbol symbol = null; if (other is ILegendGroup & (int)index != -1) legendClass = (ILege

24、ndGroup)other).get_Class(int)index); symbol = legendClass.Symbol; if (symbol = null) return; symbol = GetSymbolByControl(symbol); /symbol = GetSymbolBySymbolSelector(symbol); if (symbol = null) return; legendClass.Symbol = symbol; this.Activate(); /Fire contents changed event that the TOCControl lis

25、tens to axMapControl1.ActiveView.ContentsChanged(); /Refresh the display axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null); axTOCControl1.Update(); if (e.button = 2) esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map = null; ILayer layer = null; o

26、bject other = null; object index = null; /Determine what kind of item is selected m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); /Ensure the item gets selected if (item = esriTOCControlItem.esriTOCControlItemMap) m_tocControl.SelectItem(map, null); else m_tocCont

27、rol.SelectItem(layer, null); / Set the layer into the CustomProperty (this is used by the custom layer commands) m_mapControl.CustomProperty = layer; /Popup the correct context menu if (item = esriTOCControlItem.esriTOCControlItemMap) m_menuMap.PopupMenu(e.x, e.y, m_tocControl.hWnd); if (item = esri

28、TOCControlItem.esriTOCControlItemLayer) m_menuLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd); private ISymbol GetSymbolByControl(ISymbol symbolType) ISymbol symbol = null; IStyleGalleryItem styleGalleryItem = null; esriSymbologyStyleClass styleClass = esriSymbologyStyleClass.esriStyleClassMarkerSymbol

29、s; if (symbolType is IMarkerSymbol) styleClass = esriSymbologyStyleClass.esriStyleClassMarkerSymbols; if (symbolType is ILineSymbol) styleClass = esriSymbologyStyleClass.esriStyleClassLineSymbols; if (symbolType is IFillSymbol) styleClass = esriSymbologyStyleClass.esriStyleClassFillSymbols; GetSymbo

30、lByControlForm symbolForm = new GetSymbolByControlForm(styleClass); symbolForm.ShowDialog(); styleGalleryItem = symbolForm.m_styleGalleryItem; if (styleGalleryItem = null) return null; symbol = styleGalleryItem.Item as ISymbol; symbolForm.Dispose(); this.Activate(); return symbol; 四、心得体会本次实验过程中,值得肯定的是,已对AO开发一般流程基本掌握:新建项目、搭建框架、实现各个框架中的各个功能、添加引用与类。但是本次实验也让我认识到自己的不足,导致完成作业的整个过程比较艰难。首先发现自己在C#方面的基础比较薄弱,主要体现在,代码无法读懂;原理虽基本理解但是无法解决在此过程中遇到的问题,只能多多寻求同学的帮助;功能实现只能进行简单的模仿,无法参透其中的内涵。通过这个作业,让我明白了遇到问题只要去努力解决,不断思考、不断请教、不断尝试,就能够完成原定任务,达到目标。最后,这次作业极大的提升了我对GIS的兴趣,今后将继续领略GIS的精妙之处。 14

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 实用文档 > 工作总结

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报