《2022年ArcGIS_Engine+最短路径分析 .pdf》由会员分享,可在线阅读,更多相关《2022年ArcGIS_Engine+最短路径分析 .pdf(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、建立 network ,是把有关联的数据表之间的空间关系建立起来你可以用 arc catalog 或者 arc toolbox 中的工具来创建其实你这个问题,直接搜索一下arcgis ,创建 network,就能得到答案了呀desktop 中有向导式的工具,具体叫什么名字我忘记了,好像是在topologic 还是哪个组下面,你找一下肯定找的到的。单单用engine 是不成的using ESRI.ArcGIS.NetworkAnalysis; public class ClsPathFinder private IGeometricNetwork m_ipGeometricNetwork; pr
2、ivate 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; private IPolyline m_ipPolyline; #region Public Function /返回和设置当前地图public IMap SetOrGet
3、Map set m_ipMap = value; getreturn m_ipMap; /打开网络public void OpenFeatureDatasetNetwork(IFeatureDataset FeatureDataset) CloseWorkspace(); if (!InitializeNetworkAndMap(FeatureDataset) Console.WriteLine( 打开出错 ); /输入点的集合public IPointCollection StopPoints setm_ipPoints= value; getreturn m_ipPoints; 名师资料总
4、结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 7 页 - - - - - - - - - /路径成本public double PathCost get return m_dblPathCost; /返回路径public IPolyline PathPolyLine() IEIDInfo ipEIDInfo; IGeometry ipGeometry; if(m_ipPolyline!=null)return m_ipPolyline;m_ipPolyline = new Pol
5、ylineClass(); IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryCollection; ISpatialReference ipSpatialReference = m_ipMap.SpatialReference; IEIDHelper ipEIDHelper = new EIDHelperClass(); ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork; ipEIDHelper.OutputSpatialReference = ipSpati
6、alReference; ipEIDHelper.ReturnGeometries = true; IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges); int count = ipEnumEIDInfo.Count; ipEnumEIDInfo.Reset(); for(int i =0;icount;i+) ipEIDInfo = ipEnumEIDInfo.Next(); ipGeometry = ipEIDInfo.Geometry; ipNewGeometryColl.Add
7、GeometryCollection( ipGeometry as IGeometryCollection); return m_ipPolyline; /解决路径public void SolvePath(string WeightName) try int intEdgeUserClassID; int intEdgeUserID; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 7 页 - - - - - - - - - int intEdgeUserSubID;
8、int intEdgeID; IPoint ipFoundEdgePoint; double dblEdgePercent; /*C# 中使用*ITraceFlowSolverGEN替代 ITraceFlowSolver */ ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver; INetwork ipNetwork = m_ipGeometricNet
9、work.Network; ipNetSolver.SourceNetwork = ipNetwork; INetElements ipNetElements = ipNetwork as INetElements; int intCount = m_ipPoints.PointCount; /定义一个边线旗数组IEdgeFlag pEdgeFlagList = new EdgeFlagClassintCount; for(int i = 0;iintCount ;i+) INetFlag ipNetFlag = new EdgeFlagClass()as INetFlag; IPoint i
10、pEdgePoint = m_ipPoints.get_Point(i);/查找输入点的最近的边线m_ipPointToEID.GetNearestEdge(ipEdgePoint, out intEdgeID,out ipFoundEdgePoint, out dblEdgePercent); ipNetElements.QueryIDs( intEdgeID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID,out intEdgeUserSubID); ipNetFlag.UserClassID =
11、 intEdgeUserClassID; ipNetFlag.UserID = intEdgeUserID; ipNetFlag.UserSubID = intEdgeUserSubID; IEdgeFlag pTemp = (IEdgeFlag)(ipNetFlag as IEdgeFlag); pEdgeFlagList=pTemp; ipTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList); INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = i
12、pNetSchema.get_WeightByName(WeightName); INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights; ipNetSolverWeights.FromToEdgeWeight = ipNetWeight;/开始边线的权重ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight;/终止边线的权重object vaRes =new objectintCount-1; /通过 findpath 得到边线和交汇点的集合ipTr
13、aceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 7 页 - - - - - - - - - esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges, intCount-1, ref vaRes); /计算成本m_dblPathCost
14、 = 0; for (int i =0;ivaRes.Length;i+) double m_Va =(double) vaRes; m_dblPathCost = m_dblPathCost + m_Va; m_ipPolyline = null; catch(Exception ex) Console.WriteLine(ex.Message); #endregion #region Private Function /初始化private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset) IFeatureClassC
15、ontainer ipFeatureClassContainer; IFeatureClass ipFeatureClass ; IGeoDataset ipGeoDataset; ILayer ipLayer ; IFeatureLayer ipFeatureLayer; IEnvelope ipEnvelope, ipMaxEnvelope ; double dblSearchTol; INetworkCollection ipNetworkCollection = FeatureDataset as INetworkCollection;int count = ipNetworkColl
16、ection.GeometricNetworkCount; /获取几何网络工作空间m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0); INetwork ipNetwork = m_ipGeometricNetwork.Network; if(m_ipMap!=null) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 7 页 - - - - - - - - - m_ipMap = new
17、MapClass(); ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer; count = ipFeatureClassContainer.ClassCount; for(int i =0;icount;i+) ipFeatureClass = ipFeatureClassContainer.get_Class(i); ipFeatureLayer = new FeatureLayerClass(); ipFeatureLayer.FeatureClass = ipFeatureClass; m_i
18、pMap.AddLayer( ipFeatureLayer); count = m_ipMap.LayerCount; ipMaxEnvelope = new EnvelopeClass(); for(int i =0;i dblHeight) dblSearchTol = dblWidth / 100; else dblSearchTol = dblHeight / 100; m_ipPointToEID.SnapTolerance = dblSearchTol; return true ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - -
19、 - - - 名师精心整理 - - - - - - - 第 5 页,共 7 页 - - - - - - - - - private void CloseWorkspace() m_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_ipPathFin
20、der=null)/打开网络空间 m_ipPathFinder = new ClsPathFinder(); ipMap = this.m_ActiveView.FocusMap; ipLayer = ipMap.get_Layer(0); ipFeatureLayer = ipLayer as IFeatureLayer; ipFDB = ipFeatureLayer.FeatureClass.FeatureDataset; m_ipPathFinder.SetOrGetMap = ipMap; m_ipPathFinder.OpenFeatureDatasetNetwork(ipFDB);
21、 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 7 页 - - - - - - - - - private void ViewMap_OnMouseDown(object sender, ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvent e)/获取鼠标输入的点 IPoint ipNew ; if( m_ipPoints=null) m_ipPoints = new MultipointClass();
22、m_ipPathFinder.StopPoints = m_ipPoints; ipNew = V iewMap.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x,e.y); object o = Type.Missing; m_ipPoints.AddPoint(ipNew,ref o,ref o); m_ipPathFinder.SolvePath(Weight);/ 解析路径IPolyline ipPolyResult = m_ipPathFinder.PathPolyLine();/返回最短路径本 篇 文 章 来 源 于GIS空 间 站转 载 请 以 链 接 形 式 注 明 出 处网 址 :http:/ 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 7 页 - - - - - - - - -