您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 最短路径Arcengine
  所属分类: Access
  开发工具:
  文件大小: 73kb
  下载次数: 0
  上传时间: 2009-03-24
  提 供 者: yimia******
 详细说明: arcengine写的最短路径分析的核心代码 public void OpenFeatureDatasetNetwork(IFeatureDataset FeatureDataset) { CloseWorkspace(); if (!InitializeNetworkAndMap(FeatureDataset)) Console.WriteLine("打开network出错"); } //路径成本 public double PathCost { get { return m_dblPathCost; } } //返回路径的几何体 public IPolyline PathPolyLine() { IEIDInfo ipEIDInfo; IGeometry ipGeometry; if (m_ipPo lyline != null) return m_ipPolyline; m_ipPolyline = new PolylineClass(); IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryCollection;//引用传递 ISpatialReference ipSpatialReference = m_ipMap.SpatialReference; IEIDHelper ipEIDHelper = new EIDHelperClass(); ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork; ipEIDHelper.OutputSpatialReference = ipSpatialReference; ipEIDHelper.ReturnGeometries = true; IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges); int count = ipEnumEIDInfo.Count; ipEnumEIDInfo.Reset(); for (int i = 0; i < count; i++) { ipEIDInfo = ipEnumEIDInfo.Next(); ipGeometry = ipEIDInfo.Geometry; ipNewGeometryColl.AddGeometryCollection(ipGeometry as IGeometryCollection); } return m_ipPolyline; } //解决路径 public void SolvePath(string WeightName) { try { int intEdgeUserClassID; int intEdgeUserID; int intEdgeUserSubID; int intEdgeID; IPoint ipFoundEdgePoint; double dblEdgePercent; ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver; INetwork ipNetwork = m_ipGeometricNetwork.Network; ipNetSolver.SourceNetwork = ipNetwork; INetElements ipNetElements = ipNetwork as INetElements; int intCount = m_ipPoints.PointCount;//这里的points有值吗? //定义一个边线旗数组 IEdgeFlag[] pEdgeFlagList = new EdgeFlagClass[intCount]; for (int i = 0; i < intCount; i++) { INetFlag ipNetFlag = new EdgeFlagClass() as INetFlag; IPoint ipEdgePoint = 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 = intEdgeUserClassID; ipNetFlag.UserID = intEdgeUserID; ipNetFlag.UserSubID = intEdgeUserSubID; IEdgeFlag pTemp = (IEdgeFlag)(ipNetFlag as IEdgeFlag); pEdgeFlagList[i] = pTemp; } ipTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList); INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = ipNetSchema.get_WeightByName(WeightName); INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights; ipNetSolverWeights.FromToEdgeWeight = ipNetWeight;//开始边线的权重 ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight;//终止边线的权重 object[] vaRes = new object[intCount - 1]; //通过findpath得到边线和交汇点的集合 ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, 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)vaRes[i];//我修改过 m_dblPathCost = m_dblPathCost + m_Va; } m_ipPolyline = null; } catch (Exception ex) { Console.WriteLine(ex.Message); } } //初始化几何网络和地图 private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset) { IFeatureClassContainer ipFeatureClassContainer; IFeatureClass ipFeatureClass; IGeoDataset ipGeoDataset; ILayer ipLayer; IFeatureLayer ipFeatureLayer; IEnvelope ipEnvelope, ipMaxEnvelope; double dblSearchTol; INetworkCollection ipNetworkCollection = FeatureDataset as INetworkCollection; int count = ipNetworkCollection.GeometricNetworkCount; //获取第一个几何网络工作空间 m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0); INetwork ipNetwork = m_ipGeometricNetwork.Network; if (m_ipMap != null) { //m_ipMap = new MapClass(); ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer; count = ipFeatureClassContainer.ClassCount; for (int i = 0; i < count; 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() == ipFeatureLayer.Name.ToUpper()) { continue; } } m_ipMap.AddLayer(ipFeatureLayer); } m_ipActiveView.Refresh(); } count = m_ipMap.LayerCount; ipMaxEnvelope = new EnvelopeClass(); 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_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork; double dblWidth = ipMaxEnvelope.Width; double dblHeight = ipMaxEnvelope.Height; if (dblWidth > dblHeight) dblSearchTol = dblWidth / 100; else dblSearchTol = dblHeight / 100; m_ipPointToEID.SnapTolerance = dblSearchTol; return true; } //关闭工作空间 private void CloseWorkspace() { m_ipGeometricNetwork = null; m_ipPoints = null; m_ipPointToEID = null; m_ipEnumNetEID_Junctions = null; m_ipEnumNetEID_Edges = null; m_ipPolyline = null; } public void OpenAccessNetwork(string AccessFileName, string FeatureDatasetName) { IWorkspaceFactory ipWorkspaceFactory; IWorkspace ipWorkspace; IFeatureWorkspace ipFeatureWorkspace; IFeatureDataset ipFeatureDataset; CloseWorkspace(); //open the mdb ipWorkspaceFactory = new AccessWorkspaceFactory(); ipWorkspace = ipWorkspaceFactory.OpenFromFile(AccessFileName, 0); //et the FeatureWorkspace ipFeatureWorkspace = ipWorkspace as IFeatureWorkspace; //open the FeatureDataset ipFeatureDataset = ipFeatureWorkspace.OpenFeatureDataset(FeatureDatasetName); //initialize Network and Map (m_ipNetwork, m_ipMap) if (InitializeNetworkAndMap(ipFeatureDataset)) { MessageBox.Show("Error!"); } } private void File_Open_Click(object sender, EventArgs e) { ControlsAddDataCommand adddata = new ControlsAddDataCommandClass(); adddata.OnCreate(axMapControl1.Object); adddata.OnClick(); } private void FindPath_Click(object sender, EventArgs e) { if (m_ipMap.LayerCount == 0) return; ILayer ipLayer = m_ipMap.get_Layer(0); IFeatureLayer ipFeatureLayer = ipLayer as IFeatureLayer; IFeatureDataset ipFDS = ipFeatureLayer.FeatureClass.FeatureDataset; OpenFeatureDatasetNetwork(ipFDS); clicked = true; } private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (clicked != true) return; IPoint ipNew; if (m_ipPoints == null) { m_ipPoints = new MultipointClass(); } ipNew = m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); object o = Type.Missing; m_ipPoints.AddPoint(ipNew, ref o, ref o); IElement element; ITextElement textelement = new TextElementClass(); element = textelement as IElement; clickedcount++; textelement.Text = clickedcount.ToString(); element.Geometry = m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); pGC.AddElement(element, 0); m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } private void PathSolve_Click(object sender, EventArgs e) { SolvePath("Weight");//先解析路径 IPolyline ipPolyResult = PathPolyLine();//最后返回最短路径 clicked = false; IRgbColor color = new RgbColorClass(); color.Red = 255; IElement element = new LineElementClass(); ILineSymbol linesymbol = new SimpleLineSymbolClass(); linesymbol.Color = color as IColor; linesymbol.Width = 100; element.Geometry = m_ipPolyline; pGC.AddElement(element, 2); m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); CloseWorkspace(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown(); } private void ZoomIn_Click(object sender, EventArgs e) { ControlsMapZoomInTool zoomin = new ControlsMapZoomInToolClass(); zoomin.OnCreate(axMapControl1.Object); axMapControl1.CurrentTool = (ITool)zoomin; } private void ZoomOut_Click(object sender, EventArgs e) { ControlsMapZoomOutTool zoomout = new ControlsMapZoomOutToolClass(); zoomout.OnCreate(axMapControl1.Object); axMapControl1.CurrentTool = (ITool)zoomout; } private void Pan_Click(object sender, EventArgs e) { ControlsMapPanTool pan = new ControlsMapPanToolClass(); pan.OnCreate(axMapControl1.Object); axMapControl1.CurrentTool = (ITool)pan; } private void FullExtent_Click(object sender, EventArgs e) { ControlsMapFullExtentCommand fullextent = new ControlsMapFullExtentCommandClass(); fullextent.OnCreate(axMapControl1.Object); fullextent.OnClick(); } private void select_Click(object sender, EventArgs e) { ESRI.ArcGIS.Controls.IMapControl3 pMapControl = (ESRI.ArcGIS.Controls.IMapControl3)axMapControl1.Object; pMapControl.CurrentTool = null; axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault; } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 最短路径Arcengine
 输入关键字,在本站1000多万海量源码库中尽情搜索: