GIS实验报告.docx

上传人:b****6 文档编号:3482949 上传时间:2022-11-23 格式:DOCX 页数:14 大小:599.32KB
下载 相关 举报
GIS实验报告.docx_第1页
第1页 / 共14页
GIS实验报告.docx_第2页
第2页 / 共14页
GIS实验报告.docx_第3页
第3页 / 共14页
GIS实验报告.docx_第4页
第4页 / 共14页
GIS实验报告.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

GIS实验报告.docx

《GIS实验报告.docx》由会员分享,可在线阅读,更多相关《GIS实验报告.docx(14页珍藏版)》请在冰豆网上搜索。

GIS实验报告.docx

GIS实验报告

实验报告

GIS应用软件开发

 

专业:

测绘工程

班级:

10级测绘三班

姓名:

学号:

指导教师:

胡亚

 

撰写时间:

2013年5月20日星期一

目录

一、程序运行演示2

二、问题及解决方案6

三、源程序代码7

四、心得体会14

一、程序运行演示

1.新建项目文件,并实现file中的基本功能,显示地图基本要素。

如图1

图1

2.在工具栏加载按钮,按钮功能是对当前视图缩小3倍;在工具栏加载工具,工具功能在地图上标注当前日期。

如图2

图2

按钮实现缩小3倍功能操作,如图3

图3

3.点击地图节点,弹出如图4,图5菜单并实现菜单中的内容:

图4

图5

4.点击图层节点,弹出如图6菜单并需要实现菜单中的内容

图6

5.点击LegendClass,弹出符号选择对话框,该对话框供用户按需要选择符号并进行更改。

如图7

图7

6.打开图层属性表,用户选择某条记录,可弹出如图8,9所示的右键菜单,并实现右键菜单中的内容

图8

图9

二、问题及解决方案

问题1.VS2008与2010之间要进行格式转换,按照所导向的步骤进行,否则程序将无法正常运行,出现错误

问题2.构建好基本框架后,地图文档中要素显示出现问题。

此问题要添加licence控件,否则无法显示地图要素。

问题3.使用Toolbar和Toc功能时无法进行操作

此问题应在属性设置时建立关联功能。

问题4.程序Program文件中要添加相应功能键语句,否则将无法实现功能。

问题5.引用接口,方法,例如ADF,要添加相应的引用,否则程序出现错误。

问题6.在实现两个自定义按钮与工具时,遇到的问题:

先直接引用现有项未实现,发现缺少一些东西,后自己直接创建的Basetool和Basecommand类;在代码中报错,重新生成解决方案后顺利解决这个问题。

问题7.在实现地图和图层节点的右键功能时,遇到琐碎的问题,在这个过程中直接引用老师所给的几个类,但是报错,是因为命名空间未做修改;缺少引用,需要根据错误提示添加相应的引用

三、源程序代码

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.IO;

usingSystem.Runtime.InteropServices;

usingESRI.ArcGIS.esriSystem;

usingESRI.ArcGIS.Carto;

usingESRI.ArcGIS.Controls;

usingESRI.ArcGIS.ADF;

usingESRI.ArcGIS.SystemUI;

usingESRI.ArcGIS.Display;

namespaceWindowsFormsApplication2

{

publicpartialclassMainForm:

Form

{

#regionclassprivatemembers

privateIMapControl3m_mapControl=null;

privatestringm_mapDocumentName=string.Empty;

#endregion

IMapDocumentm_MapDocument=newMapDocument();

#regionclassconstructor

privateITOCControl2m_tocControl;

privateIToolbarMenum_menuMap;

privateIToolbarMenum_menuLayer;

privateZoomIn3XCMD1test=newZoomIn3XCMD1();

publicMainForm()

{

InitializeComponent();

}

privatevoidnewDocumentToolStripMenuItem_Click(objectsender,EventArgse)

{

ICommandcommand=newCreateNewDocument();

command.OnCreate(m_mapControl.Object);

command.OnClick();

}

privatevoidopenDocumentToolStripMenuItem_Click(objectsender,EventArgse)

{

openFileDialog1.Title="SaveMapDocumentAs";

openFileDialog1.Filter="MapDocuments(*.mxd)|*.mxd";

openFileDialog1.ShowDialog();

stringsFilePath=openFileDialog1.FileName;

if(axMapControl1.CheckMxFile(sFilePath))

{

axMapControl1.MousePointer=esriControlsMousePointer.esriPointerHourglass;

axMapControl1.LoadMxFile(sFilePath,0,Type.Missing);

axMapControl1.MousePointer=esriControlsMousePointer.esriPointerDefault;

}

else

{

MessageBox.Show(sFilePath+"isnotavalidArcMapdocument");

return;

}

}

privatevoidMainForm_Load(objectsender,EventArgse)

{

//gettheMapControl

m_mapControl=(IMapControl3)axMapControl1.Object;

//disabletheSavemenu(sincethereisnodocumentyet)

this.menuSaveDoc.Enabled=false;

//定义地图右键菜单,图层右键菜单

m_tocControl=(ITOCControl2)axTOCControl1.Object;

m_mapControl=(IMapControl3)axMapControl1.Object;

//添加菜单到地图节点

m_menuMap=newToolbarMenu();

m_menuMap.AddItem("esriControls.ControlsAdddataCommand",-1,0,false,esriCommandStyles.esriCommandStyleTextOnly);

m_menuMap.AddItem(newLayerVisibility(),1,1,false,esriCommandStyles.esriCommandStyleTextOnly);

m_menuMap.AddItem(newLayerVisibility(),2,2,false,esriCommandStyles.esriCommandStyleTextOnly);

//添加菜单到图层节点

m_menuLayer=newToolbarMenu();

m_menuLayer.AddItem(newOpenAttributeTableCmd(),-1,0,false,esriCommandStyles.esriCommandStyleIconAndText);//右键添加属性表

m_menuLayer.AddItem(newRemoveLayer(),1,1,false,esriCommandStyles.esriCommandStyleTextOnly);

m_menuLayer.AddItem(newRemoveLayer(),1,2,true,esriCommandStyles.esriCommandStyleTextOnly);

m_menuLayer.AddItem(newScaleThresholds(),2,3,false,esriCommandStyles.esriCommandStyleTextOnly);

m_menuLayer.AddItem(newScaleThresholds(),3,4,false,esriCommandStyles.esriCommandStyleTextOnly);

m_menuLayer.AddItem(newLayerSelectable(),1,5,true,esriCommandStyles.esriCommandStyleTextOnly);

m_menuLayer.AddItem(newLayerSelectable(),2,6,false,esriCommandStyles.esriCommandStyleTextOnly);

m_menuLayer.AddItem(newZoomToLayer(),-1,7,true,esriCommandStyles.esriCommandStyleTextOnly);

//Setthehookofeachmenu

m_menuLayer.SetHook(m_mapControl);

m_menuMap.SetHook(m_mapControl);

axToolbarControl1.AddItem(test,-1,-1,true,0,esriCommandStyles.esriCommandStyleIconAndText);

axToolbarControl1.AddItem(newAddDateTool(),-1,-1,false,0,

esriCommandStyles.esriCommandStyleIconAndText);

}

privatevoidsaveDocumentToolStripMenuItem_Click(objectsender,EventArgse)

{

//executeSaveDocumentcommand

if(m_mapControl.CheckMxFile(m_mapDocumentName))

{

//createanewinstanceofaMapDocument

IMapDocumentmapDoc=newMapDocument();

mapDoc.Open(m_mapDocumentName,string.Empty);

//MakesurethattheMapDocumentisnotreadonly

if(mapDoc.get_IsReadOnly(m_mapDocumentName))

{

MessageBox.Show("Mapdocumentisreadonly!

");

mapDoc.Close();

return;

}

//Replaceitscontentswiththecurrentmap

mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);

//savetheMapDocumentinordertopersistit

mapDoc.Save(mapDoc.UsesRelativePaths,false);

//closetheMapDocument

mapDoc.Close();

}

}

#endregion

privatevoidsaveAsToolStripMenuItem_Click(objectsender,EventArgse)

{

//executeSaveAsDocumentcommand

ICommandcommand=newControlsSaveAsDocCommand();

command.OnCreate(m_mapControl);

command.OnClick();

}

privatevoidexitToolStripMenuItem_Click(objectsender,EventArgse)

{

Application.Exit();

}

privatevoidaxMapControl1_OnMouseMove(objectsender,IMapControlEvents2_OnMouseMoveEvente)

{

statusBarXY.Text=string.Format("{0},{1}{2}",e.mapX.ToString("#######.##"),e.mapY.ToString("#######.##"),axMapControl1.MapUnits.ToString().Substring(4));

}

privatevoidaxMapControl1_OnMapReplaced(objectsender,IMapControlEvents2_OnMapReplacedEvente)

{

test.m_activeView=this.axMapControl1.ActiveView;//添加两个工具时添加

//getthecurrentdocumentnamefromtheMapControl

m_mapDocumentName=m_mapControl.DocumentFilename;

//ifthereisnoMapDocument,diabletheSavemenuandclearthestatusbar

if(m_mapDocumentName==string.Empty)

{

menuSaveDoc.Enabled=false;

statusBarXY.Text=string.Empty;

}

else

{

//enabletheSavemanuandwritethedocnametothestatusbar

menuSaveDoc.Enabled=true;

statusBarXY.Text=Path.GetFileName(m_mapDocumentName);

}

}

privatevoidaxTOCControl1_OnMouseDown(objectsender,ITOCControlEvents_OnMouseDownEvente)

{

if(e.button==1)

{

//IBasicMapmap=newMap();

IMapMap=newMap();

IBasicMapmap=(IBasicMap)Map;

ILayerlayer=newFeatureLayer();

objectother=newobject();

objectindex=newobject();

esriTOCControlItemitem=newesriTOCControlItem();

//Determinewhatkindofitemhasbeenclickedon

axTOCControl1.HitTest(e.x,e.y,refitem,refmap,reflayer,refother,refindex);

//QItoIFeatureLayerandIGeoFeatuerLayerinterface

if(layer==null)return;

IFeatureLayerfeatureLayer=layerasIFeatureLayer;

if(featureLayer==null)return;

IGeoFeatureLayergeoFeatureLayer=(IGeoFeatureLayer)featureLayer;

ILegendClasslegendClass=newLegendClass();

ISymbolsymbol=null;

if(otherisILegendGroup&&(int)index!

=-1)

{

legendClass=((ILegendGroup)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();

//FirecontentschangedeventthattheTOCControllistensto

axMapControl1.ActiveView.ContentsChanged();

//Refreshthedisplay

axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography,null,null);

axTOCControl1.Update();

}

if(e.button==2)

{

esriTOCControlItemitem=esriTOCControlItem.esriTOCControlItemNone;

IBasicMapmap=null;ILayerlayer=null;

objectother=null;objectindex=null;

//Determinewhatkindofitemisselected

m_tocControl.HitTest(e.x,e.y,refitem,refmap,reflayer,refother,refindex);

//Ensuretheitemgetsselected

if(item==esriTOCControlItem.esriTOCControlItemMap)

m_tocControl.SelectItem(map,null);

else

m_tocControl.SelectItem(layer,null);

//SetthelayerintotheCustomProperty(thisisusedbythecustomlayercommands)

m_mapControl.CustomProperty=layer;

//Popupthecorrectcontextmenu

if(item==esriTOCControlItem.esriTOCControlItemMap)m_menuMap.PopupMenu(e.x,e.y,m_tocControl.hWnd);

if(item==esriTOCControlItem.esriTOCControlItemLayer)m_menuLayer.PopupMenu(e.x,e.y,m_tocControl.hWnd);

}

}

privateISymbolGetSymbolByControl(ISymbolsymbolType)

{

ISymbolsymbol=null;

IStyleGalleryItemstyleGalleryItem=null;

esriSymbologyStyleClassstyleClass=esriSymbologyStyleClass.esriStyleClassMarkerSymbols;

if(symbolTypeisIMarkerSymbol)

{

styleClass=esriSymbologyStyleClass.esriStyleClassMarkerSymbols;

}

if(symbolTypeisILineSymbol)

{

styleClass=esriSymbologyStyleClass.esriStyleClassLineSymbols;

}

if(symbolTypeisIFillSymbol)

{

styleClass=esriSymbologyStyleClass.esriStyleClassFillSymbols;

}

GetSymbolByControlFormsymbolForm=newGetSymbolByControlForm(styleClass);

symbolForm.ShowDialog();

styleGalleryItem=symbolForm.m_styleGalleryItem;

if(styleGalleryItem==null)returnnull;

symbol=styleGalleryItem.ItemasISymbol;

symbolForm.Dispose();

this.Activate();

returnsymbol;

}

}

}

四、心得体会

本次实验过程中,值得肯定的是,已对AO开发一般流程基本掌握:

新建项目、搭建框架、实现各个框架中的各个功能、添加引用与类。

但是本次实验也让我认识到自己的不足,导致完成作业的整个过程比较艰难。

首先发现自己在C#方面的基础比较薄弱,主要体现在,代码无法读懂;原理虽基本理解但是无法解决在此过程中遇到的问题,只能多多寻求同学的帮助;功能实现只能进行简单的模仿,无法参透其中的内涵。

通过这个作业,让我明白了遇到问题只要去努力解决,不断思考、不断请教、不断尝

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

当前位置:首页 > PPT模板 > 可爱清新

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1