版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、最短路径分析(源码)using System; ArcEngine using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.NetworkAnalysis;namespace GisEditor/ <summary>/ 最短路径分析/ </summary>public class ClsPathFinder private IGeometricNetwork m_ipGeometricNetwork;
2、60; private IMap m_ipMap; private IPointCollection m_ipPoints; private IPointToEID m_ipPointToEID; private double m_dblPathCost =0; private IEnumNetEID m_ipEnumNetEID_Junctions; private IEnumNetEID m_ipEnumNetEID_Edges; pr
3、ivate IPolyline m_ipPolyline; #region Public Function /返回和设置当前地图 public IMap SetOrGetMap set m_ipMap = value; getreturn m_ipMap; /打开几何数据集的网络工作空间
4、60; public void OpenFeatureDatasetNetwork(IFeatureDataset FeatureDataset) CloseWorkspace(); if (!InitializeNetworkAndMap(FeatureDataset) Console.WriteLine( "打开network出错"); /输
5、入点的集合 public IPointCollection StopPoints setm_ipPoints= value; getreturn m_ipPoints; /路径成本 public double PathCost get return m_dblPathC
6、ost; /返回路径的几何体 public IPolyline PathPolyLine() IEIDInfo ipEIDInfo; IGeometry ipGeometry; if(m_ipPolyline!=null)return m_ipPolyline;
7、; m_ipPolyline = new PolylineClass(); IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryCollection; ISpatialReference ipSpatialReference = m_ipMap.SpatialReference; IEIDHelper ipEIDHelper = new EIDHelperClas
8、s(); ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork; ipEIDHelper.OutputSpatialReference = ipSpatialReference; ipEIDHelper.ReturnGeometries = true; IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipE
9、numNetEID_Edges); int count = ipEnumEIDInfo.Count; ipEnumEIDInfo.Reset(); for(int i =0;i<count;i+) ipEIDInfo = ipEnumEIDInfo.Next(); ipGeometry = ipEIDInfo.Geometry;
10、; ipNewGeometryColl.AddGeometryCollection( ipGeometry as IGeometryCollection); return m_ipPolyline; /解决路径 public void SolvePath(string WeightName) try
11、160; int intEdgeUserClassID; int intEdgeUserID; int intEdgeUserSubID; int intEdgeID; IPoint ipFoundEdgePoint; double dblEdgePercent;
12、 /*PutEdgeOrigins方法的第二个参数要求是IEdgeFlag类型的数组, * 在VB等其他语言的代码中,只需传人该类型数组的第一个元素即 * 可,但C#中的机制有所不同,需要作出如下修改:使用 * ITraceFlowSolverGEN替代ITraceFlowSolver &
13、#160; */ ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver; INetwork ipNetwork = m_ipGeometricNetwork.Network;
14、160; ipNetSolver.SourceNetwork = ipNetwork; INetElements ipNetElements = ipNetwork as INetElements; int intCount = m_ipPoints.PointCount; /定义一个边线旗数组 IEdgeFlag pEdgeFlagList = new EdgeFlagClass
15、intCount; for(int i = 0;i<intCount ;i+) INetFlag ipNetFlag = new EdgeFlagClass()as INetFlag; IPoint ipEdgePoint = m_ipPoints.get_Point(i);
16、160; /查找输入点的最近的边线 m_ipPointToEID.GetNearestEdge(ipEdgePoint, out intEdgeID,out ipFoundEdgePoint, out dblEdgePercent); ipNetElements.QueryIDs( intEdgeID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdge
17、UserID,out intEdgeUserSubID); ipNetFlag.UserClassID = intEdgeUserClassID; ipNetFlag.UserID = intEdgeUserID; ipNetFlag.UserSubID = intEdgeUserSubID; IEdgeFlag pTemp = (IEdgeFlag)(i
18、pNetFlag as IEdgeFlag); pEdgeFlagListi=pTemp; ipTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList); INetSchema ipNetSchema = ipNetwork as INetSchema;
19、INetWeight ipNetWeight = ipNetSchema.get_WeightByName(WeightName); INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights; ipNetSolverWeights.FromToEdgeWeight = ipNetWeight;/开始边线的权重 ipNetSolverWeights.ToFr
20、omEdgeWeight = ipNetWeight;/终止边线的权重 object vaRes =new objectintCount-1; /通过findpath得到边线和交汇点的集合 ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum,
21、0; out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges, intCount-1, ref vaRes); /计算元素成本 m_dblPathCost = 0; for (int i =0;i<vaRes.Length;i+) dou
22、ble m_Va =(double) vaResi; m_dblPathCost = m_dblPathCost + m_Va; m_ipPolyline = null; catch(Exception ex) Cons
23、ole.WriteLine(ex.Message); #endregion #region Private Function /初始化几何网络和地图 private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset) IFeatureClassContainer ipFeatureClassContaine
24、r; IFeatureClass ipFeatureClass ; IGeoDataset ipGeoDataset; ILayer ipLayer ; IFeatureLayer ipFeatureLayer; IEnvelope ipEnvelope, ipMaxEnvelope ; double dblSearchTol; INetwork
25、Collection ipNetworkCollection = FeatureDataset as INetworkCollection; int count = ipNetworkCollection.GeometricNetworkCount; /获取第一个几何网络工作空间 m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0); INetwork ipNetwork
26、= m_ipGeometricNetwork.Network; if(m_ipMap!=null) m_ipMap = new MapClass(); ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer; count = ipFeatureClassContainer.ClassCoun
27、t; for(int i =0;i<count;i+) ipFeatureClass = ipFeatureClassContainer.get_Class(i); ipFeatureLayer = new FeatureLayerClass();
28、0; ipFeatureLayer.FeatureClass = ipFeatureClass; m_ipMap.AddLayer( ipFeatureLayer); count = m_ipMap.LayerCount; ipMaxEnvelope = new EnvelopeClass();
29、 for(int i =0;i<count;i+) ipLayer = m_ipMap.get_Layer(i); ipFeatureLayer = ipLayer as IFeatureLayer; ipGeoDataset = ipFeatureLayer as IGeoDataset; ipEnv
30、elope = ipGeoDataset.Extent; ipMaxEnvelope.Union( ipEnvelope); m_ipPointToEID = new PointToEIDClass(); m_ipPointToEID.SourceMap = m_ipMap; m_ipPointToEID.GeometricNetwork = m_ipGe
31、ometricNetwork; double dblWidth = ipMaxEnvelope.Width; double dblHeight = ipMaxEnvelope.Height; if( dblWidth > dblHeight) dblSearchTol = dblWidth / 100; else dblSearchTol = dblH
32、eight / 100; m_ipPointToEID.SnapTolerance = dblSearchTol; return true ; /关闭工作空间 private void CloseWorkspace() m_
33、ipGeometricNetwork = null; m_ipPoints = null; m_ipPointToEID = null; m_ipEnumNetEID_Junctions = null; m_ipEnumNetEID_Edges = null; m_ipPolyline = null; #endregion备注:在调用该类时的次序:ClsPathFinder m_ipPathFinder;if(m_ipPathFinder=null)/打开几何网络工作空间 m_ipPathFinder = new ClsPathFinder();
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 延安大学《色彩构成》2021-2022学年第一学期期末试卷
- 烟台理工学院《Java应用程序开发》2023-2024学年第一学期期末试卷
- 烟台大学《GMDSS通信英语》2023-2024学年第一学期期末试卷
- 股份回购合同三篇
- 制定个人品牌建设计划
- 规划未来的职业路径计划
- 信阳师范大学《计算机组成原理》2022-2023学年第一学期期末试卷
- 班级自我管理与自主学习计划
- 秘书工作流程优化方案计划
- 西华师范大学《英语阅读》2021-2022学年第一学期期末试卷
- 安全教育课件《如何拒绝校园暴力》
- 《谈判技巧与技术》课件
- 2024年九年级语文中考专题复习现代文阅读(含答案)
- 2024年高考全国甲卷英语试卷(含答案)
- 2024年贵州公需科目答案
- 数控机床考试试题附答案
- 朝花夕拾-无常解析
- 餐饮服务电子教案 学习任务4 鸡尾酒调制
- 国有企业职业经理人绩效考核制度
- 九年级第一学期家长会公开课获奖课件百校联赛一等奖课件
- 第5章 定性研究方法课件
评论
0/150
提交评论