GIS软件工程实习报告(最短路径分析).docx

上传人:doc321 文档编号:12827461 上传时间:2021-12-06 格式:DOCX 页数:25 大小:421.12KB
返回 下载 相关 举报
GIS软件工程实习报告(最短路径分析).docx_第1页
第1页 / 共25页
GIS软件工程实习报告(最短路径分析).docx_第2页
第2页 / 共25页
GIS软件工程实习报告(最短路径分析).docx_第3页
第3页 / 共25页
GIS软件工程实习报告(最短路径分析).docx_第4页
第4页 / 共25页
亲,该文档总共25页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《GIS软件工程实习报告(最短路径分析).docx》由会员分享,可在线阅读,更多相关《GIS软件工程实习报告(最短路径分析).docx(25页珍藏版)》请在三一文库上搜索。

1、.AE 开发之基于几何网络的最短路径分析1、实习目的本次实习目的在于熟练掌握ArcGIS Engine 开发工具并能够通过C#语言在 VS 2010 开发环境中完成查询几何网络的最短路径分析的功能。2、实习时间2015 年 5 月 23 日星期六3、实习内容3.1 实验环境操作系统 :Windows 2007二次开发平台 :VS 2010 开发环境 、ArcGIS Desktop10.0 、AE 开发组件3.2 实验任务完成基于几何网络分析的最短路径查询功能 ,即实现通过在几何网络地图中指定起始点 ,能够查询经过起始点的最短路线 ,并能.专业专注.够通过缩放功能在地图窗口居中显示。3.3 实验

2、步骤新建项目选择文件新建项目 ,如图选择项目类型中Visual C# ,再选择WindowsApplication ,记为 “FindShortPath ”,点击确定 。.专业专注.添加控件控件绑定因为添加的控件只是单独存在,但是程序需要各控件间协同工作,因此要进行控件绑定 。.专业专注.创建几何网络1.在 ArcCataLog中新建个人地理数据库“甘地的个人地理数据库”,然后新建要素数据集 “road ”,接着 ,鼠标右键选择要素数据集“road ”,选择 “导入要素类 ”,导入需要创建几何网络的要素类“主要公路 ”,输出要素类的名字改为“road ”,如下图所示 :2.鼠标右键选择要素数据

3、集“road ”,选择新建 “几何网络 ”,则出现 “新建几何网络 ”对话框 ,作如下图所示的一系列设置,最终得到几何网络 “road_Net ”。.专业专注.专业专注.至此,得到几何网络 “road_Net ”,如下图所示 :.专业专注.代码实现最短路径分析设置 ToolStrip1添加代码private IActiveView m_ipActiveView;private IMap m_ipMap;/地图控件中地图private IGraphicsContainer pGC;/图形对象private bool clicked = false;int clickedcount = 0;pri

4、vate double m_dblPathCost = 0;private IGeometricNetwork m_ipGeometricNetwork;private IPointCollection m_ipPoints;/输入点集合private IPointToEID m_ipPointToEID;.专业专注.private IEnumNetEID m_ipEnumNetEID_Junctions;private IEnumNetEID m_ipEnumNetEID_Edges;private IPolyline m_ipPolyline;private IMapControl3 ma

5、pctrlMainMap = null;private void Form1_Load(object sender, EventArgs e)/ 对象初始化mapctrlMainMap=m_ipActiveView = axMapControl1.ActiveView;m_ipMap = m_ipActiveView.FocusMap;clicked = false;pGC = m_ipMap as IGraphicsContainer;private void Findpath_Click(object sender, EventArgs e)mapctrlMainMap.CurrentTo

6、ol = null;/ 设置鼠标样式axMapControl1.MousePointer=esriControlsMousePointer.esriPointerCrosshair;if (axMapControl1.LayerCount = 0).专业专注.MessageBox.Show(" 请先加载几何网络数据 !");return;m_ipActiveView = axMapControl1.ActiveView;m_ipMap = m_ipActiveView.FocusMap;clicked = false;pGC = m_ipMap as IGraphicsCo

7、ntainer;ILayer ipLayer = m_ipMap.get_Layer(0);IFeatureLayer ipFeatureLayer = ipLayer as IFeatureLayer;IFeatureDatasetipFDS=OpenFeatureDatasetNetwork(ipFDS);clicked = true;clickedcount = 0;pGC.DeleteAllElements();private void SolvePath_Click(object sender, EventArgs e).专业专注.axMapControl1.MousePointer

8、=esriControlsMousePointer.esriPointerDefault;if (SolvePathGan("Weight")/先解析路径IPolylineipPolyResult= PathPolyLine();/ 最后返回最短路径clicked = false;if (ipPolyResult.IsEmpty)MessageBox.Show(" 没有路径可到 !");elseIRgbColor color = new RgbColorClass();color.Red = 255;color.Blue = 64;color.Green

9、 = 128;LineElementClasselement=newLineElementClass();ILineSymbollinesymbol=newSimpleLineSymbolClass();linesymbol.Color = color as IColor;.专业专注.linesymbol.Width = 3;element.Geometry = m_ipPolyline;element.Symbol = linesymbol;pGC.AddElement(element, 0);m_ipActiveView.PartialRefresh(esriViewDrawPhase.e

10、sriViewGraphics,null,null);axMapControl1.FlashShape(element.Geometry);MessageBox.Show("路径经过"+m_ipEnumNetEID_Edges.Count+" 条线 " + "rn"+ " 经过节点数为" +m_ipEnumNetEID_Junctions.Count+"rn"+" 路 线 长 度 为 "+几何路径信息 ");/ 路径缩放功能private void SuoFang_

11、Click(object sender, EventArgs e)if (m_ipPolyline = null).专业专注.MessageBox.Show(" 当前没有执行路径查询! 请确认!");else#region自定义路径查询函数publicvoidOpenFeatureDatasetNetwork(IFeatureDatasetFeatureDataset)CloseWorkspace();if (!InitializeNetworkAndMap(FeatureDataset)Console.WriteLine(" 打开 network 出错 &quo

12、t;);/ 关闭工作空间private void CloseWorkspace()m_ipGeometricNetwork = null;m_ipPoints = null;.专业专注.m_ipPointToEID = null;m_ipEnumNetEID_Junctions = null;m_ipEnumNetEID_Edges = null;m_ipPolyline = null;/ 初始化几何网络和地图privateboolInitializeNetworkAndMap(IFeatureDatasetFeatureDataset)IFeatureClassContainer ipFea

13、tureClassContainer;IFeatureClass ipFeatureClass;IGeoDataset ipGeoDataset;ILayer ipLayer;IFeatureLayer ipFeatureLayer;IEnvelope ipEnvelope, ipMaxEnvelope;double dblSearchTol;INetworkCollectionipNetworkCollection=FeatureDatasetas INetworkCollection;int count = ipNetworkCollection.GeometricNetworkCount

14、;/ 获取第一个几何网络工作空间m_ipGeometricNetwork=ipNetworkCollection.get_GeometricNetwork(0);.专业专注.INetwork ipNetwork = m_ipGeometricNetwork.Network;if (m_ipMap != null)ipFeatureClassContainer= m_ipGeometricNetworkasIFeatureClassContainer;count = ipFeatureClassContainer.ClassCount;for (int i = 0; i < count;

15、i+)ipFeatureClass=ipFeatureClassContainer.get_Class(i);ipFeatureLayer = new FeatureLayerClass();ipFeatureLayer.FeatureClass = ipFeatureClass;for (int j = 0; j < m_ipMap.LayerCount; j+)if(m_ipMap.get_Layer(j).Name.ToUpper()=continue;.专业专注.count = m_ipMap.LayerCount;ipMaxEnvelope = new EnvelopeClas

16、s();for (int i = 0; i < count; i+)ipLayer = m_ipMap.get_Layer(i);ipFeatureLayer = ipLayer as IFeatureLayer;ipGeoDataset = ipFeatureLayer as IGeoDataset;ipEnvelope = ipGeoDataset.Extent;ipMaxEnvelope.Union(ipEnvelope);m_ipPointToEID = new PointToEIDClass();m_ipPointToEID.SourceMap = m_ipMap;m_ipPo

17、intToEID.GeometricNetwork=m_ipGeometricNetwork;double dblWidth = ipMaxEnvelope.Width;double dblHeight = ipMaxEnvelope.Height;if (dblWidth > dblHeight)dblSearchTol = dblWidth / 100;elsedblSearchTol = dblHeight / 100;m_ipPointToEID.SnapTolerance = dblSearchTol;return true;.专业专注./ 返回路径的几何体public IPo

18、lyline PathPolyLine()IEIDInfo ipEIDInfo;IGeometry ipGeometry;if (m_ipPolyline != null) return m_ipPolyline;m_ipPolyline = new PolylineClass();IGeometryCollection ipNewGeometryColl = m_ipPolyline asIGeometryCollection;/引用传递ISpatialReferenceipSpatialReference=m_ipMap.SpatialReference;IEIDHelper ipEIDH

19、elper = new EIDHelper();ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork;ipEIDHelper.OutputSpatialReference = ipSpatialReference;ipEIDHelper.ReturnGeometries = true;IEnumEIDInfoipEnumEIDInfo=ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges);int count = ipEnumEIDInfo.Count;ipEnumEIDInfo.Reset();

20、for (int i = 0; i < count; i+).专业专注.string info;info = new stringcount;ipEIDInfo = ipEnumEIDInfo.Next();ipGeometry = ipEIDInfo.Geometry;ipNewGeometryColl.AddGeometryCollection(ipGeometryasIGeometryCollection);return m_ipPolyline;public bool SolvePathGan(string WeightName)tryint intJunctionUserCla

21、ssID;int intJunctionUserID;int intJunctionUserSubID;int intJunctionID;IPoint ipFoundJunctionPoint;.专业专注.ITraceFlowSolverGENipTraceFlowSolver=newTraceFlowSolver() as ITraceFlowSolverGEN;INetSolveripNetSolver=ipTraceFlowSolverasINetSolver;if (m_ipGeometricNetwork = null)return false;INetworkipNetwork=

22、m_ipGeometricNetwork.Network;ipNetSolver.SourceNetwork = ipNetwork;INetElementsipNetElements=ipNetworkasINetElements;if (m_ipPoints = null) MessageBox.Show(" 请选择点 !"); return false; int intCount= m_ipPoints.PointCount;/这里的points有值吗?/ 定义一个边线旗数组/*最近点 */IJunctionFlagpJunctionFlagList=newJunct

23、ionFlagintCount;for (int i = 0; i < intCount; i+).专业专注.INetFlagipNetFlag=newJunctionFlag()asINetFlag;IPoint ipJunctionPoint = m_ipPoints.get_Point(i);/ 查找输入点的最近的网络点m_ipPointToEID.GetNearestJunction(ipJunctionPoint,outintJunctionID,outipFoundJunctionPoint);ipNetElements.QueryIDs(intJunctionID,esri

24、ElementType.esriETJunction,outintJunctionUserClassID,outintJunctionUserID, out intJunctionUserSubID);ipNetFlag.UserClassID = intJunctionUserClassID;ipNetFlag.UserID = intJunctionUserID;ipNetFlag.UserSubID = intJunctionUserSubID;IJunctionFlag pTemp = (IJunctionFlag)(ipNetFlag asIJunctionFlag);pJuncti

25、onFlagListi = pTemp;ipTraceFlowSolver.PutJunctionOrigins(refpJunctionFlagList);INetSchema ipNetSchema = ipNetwork as INetSchema;.专业专注.INetWeightipNetWeight=ipNetSchema.get_WeightByName(WeightName);INetSolverWeightsipNetSolverWeights=ipTraceFlowSolver as INetSolverWeights;ipNetSolverWeights.FromToEdg

26、eWeight=ipNetWeight;/开始边线的权重ipNetSolverWeights.ToFromEdgeWeight=ipNetWeight;/终止边线的权重object vaRes = new objectintCount - 1;/ 通过 findpath 得到边线和交汇点的集合ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected,esriShortestPathObjFn.esriSPObjFnMinSum,outm_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges,in

27、tCount- 1, refvaRes);m_dblPathCost = 0;for (int i = 0; i < vaRes.Length; i+)double m_Va = (double)vaResi;m_dblPathCost = m_dblPathCost + m_Va;m_ipPolyline = null;.专业专注.return true;catch (Exception ex)Console.WriteLine(ex.Message); return false;#endregionprivatevoidaxMapControl1_OnMouseDown(object

28、sender,IMapControlEvents2_OnMouseDownEvent e)if (clicked != true)return;IPoint ipNew;if (m_ipPoints = null)m_ipPoints = new Multipoint();.专业专注.ipNew=object o = Type.Missing;m_ipPoints.AddPoint(ipNew, ref o, ref o);IElement element;ITextElement textelement = new TextElementClass();element = texteleme

29、nt as IElement;clickedcount+;textelement.Text = clickedcount.ToString();element.Geometry=pGC.AddElement(element, 0);m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);.专业专注.3.4 实验结果在得到的窗口中加载 “甘地的个人地理数据库”(在压缩包中有 )中的几何网络 “road_Net ”,将几何网络地图加载到地图显示窗口中,如下图所示 :.专业专注.点击图标添加起始点 ,效果

30、如下图 :然后点击图标,计算最短路径 ,效果如下图 :.专业专注.最后点击图标得到最短路径的缩放 ,效果如下图 :这样就完成了最短路径的查询分析和显示的功能。4、实习总结在整个过程中所出现的问题较多,体现出个人基础的不足,程序的出错有时候出现在标点符号以及英文字母的大小写上面等等问题,这些都说明了不熟练的问题 。因此 ,二次开发的一个最重要的是勤于练习敲代码,能够对着书本的代码敲二不会出现一些不该犯的错误,然后进行下一步的提高,一步一个踏实的脚印 ,打下一个坚实的基础是非常重要。另一个重要的体会就是学会自己去查询资料 ,尽可能的通过自己的能力解决问题,实在不能解决的在向老师请教,这是在大学中一个重要的方法,因此学会独立去解决问题通过查询资料,虽然是一个困难重重的过程,但是能够学到好多有用的能力。.专业专注.

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

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1