




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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实验步骤3.3.1新建项目选择文件新建项目,如图选择项目类型
2、中Visual C#,再选择Windows Application,记为“FindShortPath”,点击确定。3.3.2添加控件3.3.3控件绑定因为添加的控件只是单独存在,但是程序需要各控件间协同工作,因此要进行控件绑定。3.3.4创建几何网络1.在ArcCataLog中新建个人地理数据库“甘地的个人地理数据库”,然后新建要素数据集“road”,接着,鼠标右键选择要素数据集“road”,选择“导入要素类”,导入需要创建几何网络的要素类“主要公路”,输出要素类的名字改为“road”,如下图所示:2.鼠标右键选择要素数据集“road”,选择新建“几何网络”,则出现“新建几何网络”对话框,作如
3、下图所示的一系列设置,最终得到几何网络“road_Net”。 至此,得到几何网络“road_Net”,如下图所示:3.3.5代码实现最短路径分析1 设置ToolStrip12 添加代码private IActiveView m_ipActiveView; private IMap m_ipMap;/地图控件中地图 private IGraphicsContainer pGC;/图形对象 private bool clicked = false; int clickedcount = 0; private double m_dblPathCost = 0; private IGeometricN
4、etwork 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 mapctrlMainMap = null;private void Form1_Load(objec
5、t sender, EventArgs e) /对象初始化 mapctrlMainMap = (IMapControl3)this.axMapControl1.Object; 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 IGraphics
7、Container; ILayer ipLayer = m_ipMap.get_Layer(0); IFeatureLayer ipFeatureLayer = ipLayer as IFeatureLayer; IFeatureDataset ipFDS = ipFeatureLayer.FeatureClass.FeatureDataset; OpenFeatureDatasetNetwork(ipFDS); clicked = true; clickedcount = 0; pGC.DeleteAllElements(); private void SolvePath_Click(obj
8、ect sender, EventArgs e) axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; if (SolvePathGan("Weight")/先解析路径 IPolyline ipPolyResult = PathPolyLine();/最后返回最短路径 clicked = false; if (ipPolyResult.IsEmpty) MessageBox.Show("没有路径可到!"); else IRgbColor color = new
9、RgbColorClass(); color.Red = 255; color.Blue = 64; color.Green = 128; LineElementClass element = new LineElementClass(); ILineSymbol linesymbol = new SimpleLineSymbolClass(); linesymbol.Color = color as IColor; linesymbol.Width = 3; element.Geometry = m_ipPolyline; element.Symbol = linesymbol; pGC.A
10、ddElement(element, 0); m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); axMapControl1.FlashShape(element.Geometry); MessageBox.Show("路径经过" + m_ipEnumNetEID_Edges.Count + "条线" + "rn" + "经过节点数为" + m_ipEnumNetEID_Junctions.Count + &q
11、uot;rn" + "路线长度为" + m_ipPolyline.Length.ToString("#.#") + "rn", "几何路径信息"); /路径缩放功能 private void SuoFang_Click(object sender, EventArgs e) if (m_ipPolyline = null) MessageBox.Show("当前没有执行路径查询!请确认!"); else this.axMapControl1.Extent = m_ipPolyline.
12、Envelope; #region 自定义路径查询函数 public void OpenFeatureDatasetNetwork(IFeatureDataset FeatureDataset) CloseWorkspace(); if (!InitializeNetworkAndMap(FeatureDataset) Console.WriteLine("打开network出错"); /关闭工作空间 private void CloseWorkspace() m_ipGeometricNetwork = null; m_ipPoints = null; m_ipPoint
13、ToEID = null; m_ipEnumNetEID_Junctions = null; m_ipEnumNetEID_Edges = null; m_ipPolyline = null; /初始化几何网络和地图 private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset) IFeatureClassContainer ipFeatureClassContainer; IFeatureClass ipFeatureClass; IGeoDataset ipGeoDataset; ILayer ipLayer; IF
14、eatureLayer ipFeatureLayer; IEnvelope ipEnvelope, ipMaxEnvelope; double dblSearchTol; INetworkCollection ipNetworkCollection = FeatureDataset as INetworkCollection; int count = ipNetworkCollection.GeometricNetworkCount; /获取第一个几何网络工作空间 m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0
15、); INetwork ipNetwork = m_ipGeometricNetwork.Network; if (m_ipMap != null) ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer; count = ipFeatureClassContainer.ClassCount; for (int i = 0; i < count; i+) ipFeatureClass = ipFeatureClassContainer.get_Class(i); ipFeatureLayer = n
16、ew FeatureLayerClass(); ipFeatureLayer.FeatureClass = ipFeatureClass; for (int j = 0; j < m_ipMap.LayerCount; j+) if (m_ipMap.get_Layer(j).Name.ToUpper() = ipFeatureLayer.Name.ToUpper() continue; count = m_ipMap.LayerCount; ipMaxEnvelope = new EnvelopeClass(); for (int i = 0; i < count; i+) ip
17、Layer = 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_ipPointToEID.GeometricNetwork = m_ip
18、GeometricNetwork; double dblWidth = ipMaxEnvelope.Width; double dblHeight = ipMaxEnvelope.Height; if (dblWidth > dblHeight) dblSearchTol = dblWidth / 100; else dblSearchTol = dblHeight / 100; m_ipPointToEID.SnapTolerance = dblSearchTol; return true; /返回路径的几何体 public IPolyline PathPolyLine() IEIDI
19、nfo ipEIDInfo; IGeometry ipGeometry; if (m_ipPolyline != null) return m_ipPolyline; m_ipPolyline = new PolylineClass(); IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryCollection;/引用传递 ISpatialReference ipSpatialReference = m_ipMap.SpatialReference; IEIDHelper ipEIDHelper = new EIDH
20、elper(); ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork; ipEIDHelper.OutputSpatialReference = ipSpatialReference; ipEIDHelper.ReturnGeometries = true; IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges); int count = ipEnumEIDInfo.Count; ipEnumEIDInfo.Reset(); for (i
21、nt i = 0; i < count; i+) string info; info = new stringcount; ipEIDInfo = ipEnumEIDInfo.Next(); ipGeometry = ipEIDInfo.Geometry; ipNewGeometryColl.AddGeometryCollection(ipGeometry as IGeometryCollection); infoi = m_ipPolyline.Length.ToString(); return m_ipPolyline; public bool SolvePathGan(string
22、 WeightName) try int intJunctionUserClassID; int intJunctionUserID; int intJunctionUserSubID; int intJunctionID; IPoint ipFoundJunctionPoint; ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolver() as ITraceFlowSolverGEN; INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver; if (m_ipGeomet
23、ricNetwork = null) return false; INetwork ipNetwork = m_ipGeometricNetwork.Network; ipNetSolver.SourceNetwork = ipNetwork; INetElements ipNetElements = ipNetwork as INetElements; if (m_ipPoints = null) MessageBox.Show("请选择点!"); return false; int intCount = m_ipPoints.PointCount;/这里的points有
24、值吗? /定义一个边线旗数组 /*最近点*/ IJunctionFlag pJunctionFlagList = new JunctionFlagintCount; for (int i = 0; i < intCount; i+) INetFlag ipNetFlag = new JunctionFlag() as INetFlag; IPoint ipJunctionPoint = m_ipPoints.get_Point(i); /查找输入点的最近的网络点 m_ipPointToEID.GetNearestJunction(ipJunctionPoint, out intJunct
25、ionID, out ipFoundJunctionPoint); ipNetElements.QueryIDs(intJunctionID, esriElementType.esriETJunction, out intJunctionUserClassID, out intJunctionUserID, out intJunctionUserSubID); ipNetFlag.UserClassID = intJunctionUserClassID; ipNetFlag.UserID = intJunctionUserID; ipNetFlag.UserSubID = intJunctio
26、nUserSubID; IJunctionFlag pTemp = (IJunctionFlag)(ipNetFlag as IJunctionFlag); pJunctionFlagListi = pTemp; ipTraceFlowSolver.PutJunctionOrigins(ref pJunctionFlagList); INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = ipNetSchema.get_WeightByName(WeightName); INetSolverWeigh
27、ts ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights; ipNetSolverWeights.FromToEdgeWeight = ipNetWeight;/开始边线的权重 ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight;/终止边线的权重 object vaRes = new objectintCount - 1; /通过findpath得到边线和交汇点的集合 ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnecte
28、d, esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges, intCount - 1, ref vaRes); 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; #endregion private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) if (clicked != true) return; IPoint ipNew; if (m_ipPoints = null) m_ipPoin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 河南省豫地科技集团招聘笔试真题2024
- 教学设计太原幼儿师范李慧芳26日改
- 职业教育产教融合实训基地建设项目可行性研究报告
- 持续创新驱动下的绿色工业人才培养与合作
- 2025至2030年中国油田阻垢缓蚀剂行业投资前景及策略咨询报告
- 2025至2030年中国榉木鼓棒行业投资前景及策略咨询报告
- 2025至2030年中国桃小清乳油行业投资前景及策略咨询报告
- 人工智能生成内容在实验室安全评估中的应用
- 六年级下册科学 八颗行星 练习题(含答案)
- 2025年船用配套设备项目立项申请报告
- 燃气轮机蒸汽轮机联合循环
- DB13-T 5821-2023 预拌流态固化土回填技术规程
- 参观河南省博物院
- 中国公民健康素养66条知识答题(试题及答案)
- 2024年一级注册计量师计量专业案例分析考试真题及答案
- 广东省佛山市南海区桂城街道2023-2024学年四年级下学期期末英语试卷
- 《财务会计基础》课件-错账更正
- 2024项目投资协议书
- 中考数学计算题练习100道(2024年中考真题)
- 统编版语文二年级上册8古诗二首 望庐山瀑布 公开课一等奖创新教学设计
- 自动控制原理 第3版 课件全套 陶洪峰 第1-8章 概论、控制系统数学模型-线性离散系统分析
评论
0/150
提交评论