public void SolvePath(string WeightName) { int num; ITraceFlowSolver solver = (ITraceFlowSolver) new TraceFlowSolverClass(); INetSolver solver2 = (INetSolver)solver; INetwork network = this.m_ipGeometricNetwork.Network; solver2.SourceNetwork = network; INetElements elements = (INetElements)network; IEdgeFlag[] edgeOrigins = new IEdgeFlag[this.m_ipPoints.PointCount + 1]; for (num = 0; num < this.m_ipPoints.PointCount; num++) { IPoint point; int num2; double num3; int num4; int num5; int num6; INetFlag flag = new EdgeFlagClass(); IPoint inputPoint = this.m_ipPoints.get_Point(num); this.m_ipPointToEID.GetNearestEdge(inputPoint, out num2, out point, out num3); elements.QueryIDs(num2, esriElementType.esriETEdge, out num4, out num5, out num6); flag.UserClassID = num4; flag.UserID = num5; flag.UserSubID = num6; edgeOrigins[num] = (IEdgeFlag)flag; } (solver as ITraceFlowSolverGEN).PutEdgeOrigins(ref edgeOrigins); try { INetSolverWeights weights = (INetSolverWeights)solver; weights.JunctionWeight = this.JunctionWeight; weights.FromToEdgeWeight = this.FromToEdgeWeight; weights.ToFromEdgeWeight = this.ToFromEdgeWeight; } catch { } object[] segmentCosts = new object[this.m_ipPoints.PointCount]; (solver as ITraceFlowSolverGEN).FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out this.m_ipEnumNetEID_Junctions, out this.m_ipEnumNetEID_Edges, this.m_ipPoints.PointCount - 1, ref segmentCosts); this.m_dblPathCost = 0.0; for (num = 0; num < segmentCosts.Length; num++) { this.m_dblPathCost += (double)segmentCosts[num]; } this.m_ipPolyline = null; }
private void btnStartAnalysis_Click(object obj, EventArgs eventArgs) { if (this._nearestEdgeInfo.GeometricNetwork != null) { this._networkInfo.arrayList_1.Clear(); this._networkInfo.arrayList_0.Clear(); INetElements netElements = (INetElements)this._nearestEdgeInfo.GeometricNetwork.Network; ITraceFlowSolver traceFlowSolver = this.GetTraceFlowSolver(); IEnumNetEID junctionEIDs; IEnumNetEID edgeEIDs; traceFlowSolver.FindFlowEndElements(this.GetFindMethod(), esriFlowElements.esriFEJunctions, out junctionEIDs, out edgeEIDs); int num; int num2; int num3; for (int i = junctionEIDs.Next(); i > 0; i = junctionEIDs.Next()) { netElements.QueryIDs(i, (esriElementType)1, out num, out num2, out num3); IFeature feature = this._networkInfo.LayerPoint.FeatureClass.GetFeature(num2); int num4 = feature.Fields.FindField(this.label1.Text); if (num4 == -1) { return; } if (this.listFieldValues.Items.IndexOf(feature.get_Value(num4)) != -1) { this._networkInfo.arrayList_0.Add(feature); } } traceFlowSolver.FindFlowElements(this.GetFindMethod(), esriFlowElements.esriFEEdges, out junctionEIDs, out edgeEIDs); for (int i = edgeEIDs.Next(); i > 0; i = edgeEIDs.Next()) { netElements.QueryIDs(i, esriElementType.esriETEdge, out num, out num2, out num3); IFeature feature2 = this._networkInfo.LayerLine.FeatureClass.GetFeature(num2); this._networkInfo.arrayList_1.Add(feature2); } m_iApp.FocusMap.ClearSelection(); this.CreateResultElements(); this.CreateBlockElements(); this.FillResultToTreeView(); } }
public ITraceFlowSolver GetTraceFlowSolver() { INetElements netElements = (INetElements)this._nearestEdgeInfo.GeometricNetwork.Network; int userClassID = 0; int userID = 0; int userSubID = 0; netElements.QueryIDs(this._nearestEdgeInfo.EdgeID, esriElementType.esriETEdge, out userClassID, out userID, out userSubID); IEdgeFlag edgeFlag = new EdgeFlag(); ((INetFlag)edgeFlag).UserClassID = (userClassID); ((INetFlag)edgeFlag).UserID = (userID); ((INetFlag)edgeFlag).UserSubID = (userSubID); ITraceFlowSolver traceFlowSolver = (ITraceFlowSolver) new TraceFlowSolver(); ((INetSolver)traceFlowSolver).SourceNetwork = (this._nearestEdgeInfo.GeometricNetwork.Network); ((INetSolver)traceFlowSolver).SelectionSetBarriers = (this.GetSelectionSetBarries()); traceFlowSolver.PutEdgeOrigins(1, ref edgeFlag); return(traceFlowSolver); }
private static ITraceFlowSolver CreateTraceFlowSolver() { int num; INetFlag netFlag; ITraceFlowSolver solver = (ITraceFlowSolver) new TraceFlowSolverClass(); INetSolver solver2 = (INetSolver)solver; INetwork network = m_pAnalystGN.Network; solver2.SourceNetwork = network; INetElements elements = (INetElements)network; if (m_JunFlags.Count > 0) { IJunctionFlag[] junctionOrigins = new IJunctionFlag[m_JunFlags.Count]; for (num = 0; num < m_JunFlags.Count; num++) { netFlag = (m_JunFlags[num] as NetFlagWrap).NetFlag; junctionOrigins[num] = (IJunctionFlag)netFlag; } (solver as ITraceFlowSolverGEN).PutJunctionOrigins(ref junctionOrigins); } if (m_EdgeFlags.Count > 0) { IEdgeFlag[] edgeOrigins = new IEdgeFlag[m_EdgeFlags.Count]; for (num = 0; num < m_EdgeFlags.Count; num++) { netFlag = (m_EdgeFlags[num] as NetFlagWrap).NetFlag; edgeOrigins[num] = (IEdgeFlag)netFlag; } (solver as ITraceFlowSolverGEN).PutEdgeOrigins(ref edgeOrigins); } INetSolverWeightsGEN sgen = (INetSolverWeightsGEN)solver; if (JunctionWeight != null) { sgen.JunctionWeight = JunctionWeight; } if (FromToEdgeWeight != null) { sgen.JunctionWeight = FromToEdgeWeight; } if (ToFromEdgeWeight != null) { sgen.JunctionWeight = ToFromEdgeWeight; } if (JunctionFilterWeight != null) { sgen.JunctionFilterWeight = JunctionFilterWeight; } if (FromToEdgeFilterWeight != null) { sgen.FromToEdgeFilterWeight = FromToEdgeFilterWeight; } if (ToFromEdgeFilterWeight != null) { sgen.ToFromEdgeFilterWeight = ToFromEdgeFilterWeight; } if (JuncfromValues != null) { sgen.SetFilterRanges(esriElementType.esriETJunction, ref JuncfromValues, ref JunctoValues); sgen.SetFilterType(esriElementType.esriETJunction, esriWeightFilterType.esriWFRange, ApplyJuncFilterWeight); } else { sgen.SetFilterType(esriElementType.esriETJunction, esriWeightFilterType.esriWFNone, ApplyJuncFilterWeight); } if (EdgefromValues != null) { sgen.SetFilterRanges(esriElementType.esriETEdge, ref EdgefromValues, ref EdgetoValues); sgen.SetFilterType(esriElementType.esriETEdge, esriWeightFilterType.esriWFRange, ApplyJuncFilterWeight); } else { sgen.SetFilterType(esriElementType.esriETEdge, esriWeightFilterType.esriWFNone, ApplyEdgeFilterWeight); } INetElementBarriers netElementBarriers = GetNetElementBarriers(esriElementType.esriETJunction); if (netElementBarriers != null) { (solver as INetSolver).set_ElementBarriers(esriElementType.esriETJunction, netElementBarriers); } netElementBarriers = GetNetElementBarriers(esriElementType.esriETEdge); if (netElementBarriers != null) { (solver as INetSolver).set_ElementBarriers(esriElementType.esriETEdge, netElementBarriers); } return(solver); }
private bool slovePath() { try { double costLength = 0; m_ipPointToEID = new PointToEIDClass(); m_ipPointToEID.SourceMap = m_HookHelper.ActiveView.FocusMap; m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork; m_ipPointToEID.SnapTolerance = m_HookHelper.ActiveView.Extent.Envelope.Width / 100; INetwork ipNetwork; INetElements ipNetElements; INetFlag ipNetFlag; //IEdgeFlag ipEdgeFlag; IEdgeFlag [] EdgeFlagArray; int pEdgeID; IPoint pLocation; double dblEdgePercent; int iUserClassID, iUserID, iUserSubID; // look up the EID for the current point (this will populate intEdgeID and dblEdgePercent) ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolver; //get the inetsolver interface ipNetSolver = ipTraceFlowSolver as INetSolver; ipNetwork = m_ipGeometricNetwork.Network; //set the net solver's source network ipNetSolver.SourceNetwork = ipNetwork; //make edge flags from the points //the INetElements interface is needed to get UserID, UserClassID, //and UserSubID from an element id EdgeFlagArray = new IEdgeFlag[mPointArray.PointCount]; ipNetElements = ipNetwork as INetElements; for (int ii = 0; ii < mPointArray.PointCount; ii++) { ipNetFlag = new EdgeFlagClass(); point = mPointArray.get_Point(ii); m_ipPointToEID.GetNearestEdge(point, out pEdgeID, out pLocation, out dblEdgePercent); //iUserClassID是featureclass ID,userID是objectID,userSubID ipNetElements.QueryIDs(pEdgeID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID); ipNetFlag.UserClassID = iUserClassID; ipNetFlag.UserID = iUserID; ipNetFlag.UserSubID = iUserSubID; EdgeFlagArray[ii] = ipNetFlag as IEdgeFlag; //MessageBox.Show(iUserID.ToString()); } //添加到TraceFlowSolver中 ITraceFlowSolverGEN pTFSolverGEN = ipTraceFlowSolver as ITraceFlowSolverGEN; pTFSolverGEN.PutEdgeOrigins(ref EdgeFlagArray); //get the INetSchema interface INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = ipNetSchema.get_Weight(0); //MessageBox.Show(ipNetWeight.WeightName); INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights; //来回使用同一个权重 ipNetSolverWeights.FromToEdgeWeight = ipNetWeight; ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight; object [] totalCost = new object[mPointArray.PointCount - 1]; pTFSolverGEN.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges, mPointArray.PointCount - 1, ref totalCost); //MessageBox.Show(totalCost[0].ToString()); for (int ii = 0; ii < totalCost.Length; ii++) { costLength += (double)(totalCost[ii]); } pStatusBar.Panels[0].Text = "水管长度:" + costLength.ToString(); return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } }
private bool slovePath() { try { double costLength=0; m_ipPointToEID = new PointToEIDClass(); m_ipPointToEID.SourceMap=m_HookHelper.ActiveView.FocusMap; m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork; m_ipPointToEID.SnapTolerance=m_HookHelper.ActiveView.Extent.Envelope.Width/100; INetwork ipNetwork; INetElements ipNetElements; INetFlag ipNetFlag; //IEdgeFlag ipEdgeFlag; IEdgeFlag [] EdgeFlagArray; int pEdgeID; IPoint pLocation; double dblEdgePercent; int iUserClassID,iUserID,iUserSubID; // look up the EID for the current point (this will populate intEdgeID and dblEdgePercent) ipTraceFlowSolver=new TraceFlowSolverClass() as ITraceFlowSolver; //get the inetsolver interface ipNetSolver=ipTraceFlowSolver as INetSolver; ipNetwork=m_ipGeometricNetwork.Network; //set the net solver's source network ipNetSolver.SourceNetwork=ipNetwork; //make edge flags from the points //the INetElements interface is needed to get UserID, UserClassID, //and UserSubID from an element id EdgeFlagArray=new IEdgeFlag[mPointArray.PointCount]; ipNetElements = ipNetwork as INetElements; for(int ii=0;ii<mPointArray.PointCount;ii++) { ipNetFlag = new EdgeFlagClass(); point=mPointArray.get_Point(ii); m_ipPointToEID.GetNearestEdge(point,out pEdgeID,out pLocation,out dblEdgePercent); //iUserClassID��featureclass ID,userID��objectID,userSubID ipNetElements.QueryIDs(pEdgeID,esriElementType.esriETEdge,out iUserClassID,out iUserID,out iUserSubID); ipNetFlag.UserClassID=iUserClassID; ipNetFlag.UserID=iUserID; ipNetFlag.UserSubID=iUserSubID; EdgeFlagArray[ii]=ipNetFlag as IEdgeFlag; //MessageBox.Show(iUserID.ToString()); } //��ӵ�TraceFlowSolver�� ITraceFlowSolverGEN pTFSolverGEN=ipTraceFlowSolver as ITraceFlowSolverGEN; pTFSolverGEN.PutEdgeOrigins(ref EdgeFlagArray); //get the INetSchema interface INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = ipNetSchema.get_Weight(0); //MessageBox.Show(ipNetWeight.WeightName); INetSolverWeights ipNetSolverWeights=ipTraceFlowSolver as INetSolverWeights; //����ʹ��ͬһ��Ȩ�� ipNetSolverWeights.FromToEdgeWeight=ipNetWeight; ipNetSolverWeights.ToFromEdgeWeight=ipNetWeight; object [] totalCost=new object[mPointArray.PointCount-1]; pTFSolverGEN.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges, mPointArray.PointCount-1,ref totalCost); //MessageBox.Show(totalCost[0].ToString()); for(int ii=0;ii<totalCost.Length;ii++){ costLength+=(double)(totalCost[ii]); } pStatusBar.Panels[0].Text="ˮ�ܳ���:"+costLength.ToString(); return true; } catch(Exception e){ MessageBox.Show(e.Message); return false; } }