/// <summary> /// Get IEnumNetEID from List of IEIDInfo /// </summary> /// <param name="eidInfos">list of IEIDInfo</param> /// <param name="elementType">element type of eid</param> /// <returns>object IEnumNetEID</returns> internal static IEnumNetEID GetEnumNetEID(List <IEIDInfo> eidInfos, esriElementType elementType) { IEnumNetEIDBuilderGEN enumNetEIDBuilder = new EnumNetEIDArrayClass(); enumNetEIDBuilder.ElementType = elementType; foreach (IEIDInfo eidInfo in eidInfos) { enumNetEIDBuilder.Add(eidInfo.EID); } return(enumNetEIDBuilder as IEnumNetEID); }
/// <summary> /// Builds the <see cref="IEnumNetEID" /> from the specified list of elements. /// </summary> /// <param name="source">The source.</param> /// <param name="elementType">Type of the element.</param> /// <param name="eids">The network element IDs.</param> /// <returns> /// A <see cref="IEnumNetEID" /> from the list of elements. /// </returns> /// <exception cref="System.ArgumentNullException">eids</exception> public static IEnumNetEID CreateEnumNetEID(this IGeometricNetwork source, esriElementType elementType, params int[] eids) { if (source == null) { return(null); } if (eids == null) { throw new ArgumentNullException("eids"); } IEnumNetEIDBuilderGEN builder = new EnumNetEIDArrayClass(); builder.ElementType = elementType; builder.Network = source.Network; builder.set_EIDs(ref eids); return((IEnumNetEID)builder); }
private void ResultBtn_Click(object sender, EventArgs e) { try { #region 设置管点分析分析条件 //为追踪任务分析器设置管点 IJunctionFlag[] arrayJunctionFlag = new IJunctionFlag[listJunctionsFlag.Count]; for (int i = 0; i < arrayJunctionFlag.Length; i++) { arrayJunctionFlag[i] = listJunctionsFlag[i]; } traceFlowsolverGen.PutJunctionOrigins(ref arrayJunctionFlag); //为追踪任务分析器设置管线 IEdgeFlag[] arrayEdgeFlag = new IEdgeFlag[listEdgeFlag.Count]; for (int i = 0; i < arrayEdgeFlag.Length; i++) { traceFlowsolverGen.PutEdgeOrigins(ref arrayEdgeFlag); } //为管点分析器设置障碍点 INetElementBarriersGEN netElementBarriersGEN = new NetElementBarriersClass(); netElementBarriersGEN.Network = m_GeometryNetwork.Network; if (JunctionBarrierEIDs.Count > 0) { int[] junctionBarrierEIDs = new int[JunctionBarrierEIDs.Count]; for (int j = 0; j < junctionBarrierEIDs.Length; j++) { junctionBarrierEIDs[j] = JunctionBarrierEIDs[j]; } netElementBarriersGEN.ElementType = esriElementType.esriETJunction; netElementBarriersGEN.SetBarriersByEID(ref junctionBarrierEIDs); netsolver.set_ElementBarriers(esriElementType.esriETJunction, netElementBarriersGEN as INetElementBarriers); } else //否则将管点设置为空 { netsolver.set_ElementBarriers(esriElementType.esriETJunction, null); } //未管点分析器设置障碍线 if (EdgeBarrierEIDs.Count > 0) { int[] edgeBarrierEIDs = new int[EdgeBarrierEIDs.Count]; for (int j = 0; j < EdgeBarrierEIDs.Count; j++) { edgeBarrierEIDs[j] = EdgeBarrierEIDs[j]; } netElementBarriersGEN.ElementType = esriElementType.esriETEdge; netElementBarriersGEN.SetBarriersByEID(ref edgeBarrierEIDs); netsolver.set_ElementBarriers(esriElementType.esriETEdge, netElementBarriersGEN as INetElementBarriers); } else //否则将管线设置为空 { netsolver.set_ElementBarriers(esriElementType.esriETEdge, null); } #endregion //定义相关变量 IEnumNetEID junctionEIDs = new EnumNetEIDArrayClass(); IEnumNetEID edgeEIDs = new EnumNetEIDArrayClass(); object[] segmentsCosts = null; object totalCost = null; int Counts = -1; #region 各种几何网络分析的结果 switch (this.AnalysisCategoryCmbx.SelectedIndex) { //查询共同祖先 case 0: traceFlowsolverGen.FindCommonAncestors(esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs); break; //查找相连接的网络要素 case 1: traceFlowsolverGen.FindFlowElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs); break; //查找网络中连接的环 case 2: traceFlowsolverGen.FindCircuits(esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs); break; //查找未连接的网络要素 case 3: traceFlowsolverGen.FindFlowUnreachedElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs); break; //查找上游路径,同时跟踪耗费 case 4: Counts = GetSegmentCounts(); segmentsCosts = new object[Counts]; traceFlowsolverGen.FindSource(esriFlowMethod.esriFMUpstream, esriShortestPathObjFn.esriSPObjFnMinSum, out junctionEIDs, out edgeEIDs, Counts, ref segmentsCosts); break; //获取网络路径,追踪网络耗费。count比所有的的标识总数少一个,但如果管点和管线标识同时存在的时候该功能不可用 case 5: if (listEdgeFlag.Count > 0 && listJunctionsFlag.Count > 0) { break; } else if (listJunctionsFlag.Count > 0) { Counts = listJunctionsFlag.Count - 1; } else if (listEdgeFlag.Count > 0) { Counts = listEdgeFlag.Count - 1; } else { break; } segmentsCosts = new object[Counts]; traceFlowsolverGen.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out junctionEIDs, out edgeEIDs, Counts, ref segmentsCosts); break; //下游追踪 case 6: traceFlowsolverGen.FindFlowElements(esriFlowMethod.esriFMDownstream, esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs); break; //查找上游路径消耗,同时获取网络追踪的耗费 case 7: totalCost = new object(); traceFlowsolverGen.FindAccumulation(esriFlowMethod.esriFMUpstream, esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs, out totalCost); break; //上游追踪 case 8: Counts = GetSegmentCounts(); segmentsCosts = new object[Counts]; traceFlowsolverGen.FindSource(esriFlowMethod.esriFMUpstream, esriShortestPathObjFn.esriSPObjFnMinSum, out junctionEIDs, out edgeEIDs, Counts, ref segmentsCosts); break; default: break; } #endregion //绘制结果图像 DrawTraceRsult(junctionEIDs, edgeEIDs); this.Mapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, this.Mapcontrol.ActiveView.Extent); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
void ITraceTask.OnTraceExecution() { // prepare the network solver ITraceFlowSolverGEN tfs = UTIL_coreTraceSetup(); if (tfs == null) { return; } // perform the trace task IEnumNetEID resultJuncs, resultEdges; ITraceTasks traceTasks = m_utilNetExt as ITraceTasks; esriFlowElements flowElements = traceTasks.TraceFlowElements; if (traceTasks.TraceEnds) { // find the features stopping the trace tfs.FindFlowEndElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges); } else { // return the traced features tfs.FindFlowElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges); } // copy the results to the class level INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt; if (resultJuncs == null) { // junctions were not returned -- create an empty enumeration IEnumNetEIDBuilder eidBuilder = new EnumNetEIDArrayClass(); eidBuilder.Network = nax.CurrentNetwork.Network; eidBuilder.ElementType = esriElementType.esriETJunction; m_resultJunctions = eidBuilder as IEnumNetEID; } else { m_resultJunctions = resultJuncs; } if (resultEdges == null) { // edges were not returned -- create an empty enumeration IEnumNetEIDBuilder eidBuilder = new EnumNetEIDArrayClass(); eidBuilder.Network = nax.CurrentNetwork.Network; eidBuilder.ElementType = esriElementType.esriETEdge; m_resultEdges = eidBuilder as IEnumNetEID; } else { m_resultEdges = resultEdges; } // update the extension with the results INetworkAnalysisExtResults naxResults = m_utilNetExt as INetworkAnalysisExtResults; naxResults.ClearResults(); // first remove the old results if (naxResults.ResultsAsSelection) { naxResults.CreateSelection(resultJuncs, resultEdges); } else { naxResults.SetResults(resultJuncs, resultEdges); } }
void ITraceTask.OnTraceExecution() { // prepare the network solver ITraceFlowSolverGEN tfs = UTIL_coreTraceSetup(); if (tfs == null) return; // perform the trace task IEnumNetEID resultJuncs, resultEdges; ITraceTasks traceTasks = m_utilNetExt as ITraceTasks; esriFlowElements flowElements = traceTasks.TraceFlowElements; if (traceTasks.TraceEnds) // find the features stopping the trace tfs.FindFlowEndElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges); else // return the traced features tfs.FindFlowElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges); // copy the results to the class level INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt; if (resultJuncs == null) { // junctions were not returned -- create an empty enumeration IEnumNetEIDBuilder eidBuilder = new EnumNetEIDArrayClass(); eidBuilder.Network = nax.CurrentNetwork.Network; eidBuilder.ElementType = esriElementType.esriETJunction; m_resultJunctions = eidBuilder as IEnumNetEID; } else { m_resultJunctions = resultJuncs; } if (resultEdges == null) { // edges were not returned -- create an empty enumeration IEnumNetEIDBuilder eidBuilder = new EnumNetEIDArrayClass(); eidBuilder.Network = nax.CurrentNetwork.Network; eidBuilder.ElementType = esriElementType.esriETEdge; m_resultEdges = eidBuilder as IEnumNetEID; } else { m_resultEdges = resultEdges; } // update the extension with the results INetworkAnalysisExtResults naxResults = m_utilNetExt as INetworkAnalysisExtResults; naxResults.ClearResults(); // first remove the old results if (naxResults.ResultsAsSelection) naxResults.CreateSelection(resultJuncs, resultEdges); else { naxResults.SetResults(resultJuncs, resultEdges); } }
private IEnumNetEID GetEnumNetEID(int eidToStartFrom, Dictionary<int, int> pathDictionary, INetwork network, IGeometricNetwork geomNet, esriElementType elemType) { IEnumNetEIDBuilder enumEIDBuilder = new EnumNetEIDArrayClass(); enumEIDBuilder.Network = network; enumEIDBuilder.ElementType = elemType; if (eidToStartFrom == -1)//Add all elements to the return dictionary { foreach (KeyValuePair<int, int> kvp in pathDictionary) { int eid = kvp.Key; //Only add to the builder if the element type (junction or edge) is of the type we are looking for if (((eid < 0) && elemType == esriElementType.esriETEdge) || ((eid > 0) && elemType == esriElementType.esriETJunction)) { enumEIDBuilder.Add(Math.Abs( eid)); } } } else { int eid = eidToStartFrom; while (eid != -99999999) // -99999999 means that there is no parent { if (((eid < 0) && elemType == esriElementType.esriETEdge) || ((eid > 0) && elemType == esriElementType.esriETJunction)) { enumEIDBuilder.Add(Math.Abs( eid)); } //Get the junction or edge that feeds this junction or edge eid = pathDictionary[eid]; } } return enumEIDBuilder as IEnumNetEID; }
public int [] FindPath(IEdgeFlag [] edgeFlags, out double length) { int [] roadIDs = {}; int [] roadIDList = {}; length = -1; try { ITraceFlowSolverGEN traceSolver = new TraceFlowSolverClass(); INetSolver solver = traceSolver as INetSolver; solver.SourceNetwork = roadNet; traceSolver.PutEdgeOrigins(ref edgeFlags); INetSchema schema = roadNet as INetSchema; INetSolverWeights netWeights = traceSolver as INetSolverWeights; INetWeight weight = schema.get_WeightByName("RoadTypeWeight"); netWeights.FromToEdgeWeight = weight; netWeights.ToFromEdgeWeight = weight; IEnumNetEID roadJunctions = new EnumNetEIDArrayClass(); IEnumNetEID roadEdges = new EnumNetEIDArrayClass(); object [] segmentCosts = new object [edgeFlags.Length]; traceSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out roadJunctions, out roadEdges, edgeFlags.Length-1, ref segmentCosts); // arrays for storing the featureclass id, object id, and subclass id roadIDs = new int[roadEdges.Count]; int [] FCIDList = new int[roadEdges.Count]; int [] SCIDList = new int[roadEdges.Count]; //index of feature fields of interest int lengthField = RoadEdge.FindField("SHAPE_Length"); //int roadIDField = RoadEdge.FindField("roadid"); //collect feature ids, roadids, and length by iterating through uid enumeration length = 0; roadIDList = new int[roadEdges.Count]; for(int i=0; i < roadEdges.Count; i++) { RoadNetElements.QueryIDs(roadEdges.Next(),ESRI.ArcGIS.Geodatabase.esriElementType.esriETEdge,out FCIDList[i], out roadIDs[i],out SCIDList[i]); roadIDList[i] = RoadEdge.GetFeature(roadIDs[i]).OID;//get_Value(roadIDField).ToString()); length += double.Parse(RoadEdge.GetFeature(roadIDs[i]).get_Value(lengthField).ToString()); } } catch(Exception err) { throw err; } return roadIDList;//roadIDs; }
public IEnumNetEID ConvertTracedElementsCollectionToEnumNetEid(IMMTracedElements tracedElements, INetwork network) { IEnumNetEID resultEnum = null; try { // we have a feedpath, now we want to extract all the elements of one type and // put them in an esri enumneteid so we can display it on the map or other fun stuff IEnumNetEIDBuilder enumNetEIDBuilder = new EnumNetEIDArrayClass(); enumNetEIDBuilder.Network = network; enumNetEIDBuilder.ElementType = (esriElementType)tracedElements.ElementType; INetElements netElements = network as INetElements; if ((netElements != null) && (esriElementType.esriETEdge == (esriElementType)tracedElements.ElementType)) { tracedElements.Reset(); IMMTracedElement tracedElement = tracedElements.Next(); while (tracedElement != null) { IEnumNetEID tempEnumNetEID = netElements.GetEIDs(tracedElement.FCID, tracedElement.OID, esriElementType.esriETEdge); tempEnumNetEID.Reset(); for (int eid = tempEnumNetEID.Next(); eid > 0; eid = tempEnumNetEID.Next()) { enumNetEIDBuilder.Add(eid); } tracedElement = tracedElements.Next(); } } else { tracedElements.Reset(); IMMTracedElement tracedElement = tracedElements.Next(); while (tracedElement != null) { enumNetEIDBuilder.Add(tracedElement.EID); tracedElement = tracedElements.Next(); } } if (enumNetEIDBuilder == null) { this.Logger.WriteLine("Builder is null"); } resultEnum = enumNetEIDBuilder as IEnumNetEID; } catch (Exception EX) { this.Logger.WriteLine(" ConvertTracedElements:" + EX.Message + " " + EX.StackTrace); } return resultEnum; }