AnsweredAssumed Answered

select the traced elements

Question asked by MariaMaldini on Feb 6, 2015
Latest reply on Mar 21, 2018 by spencer_han

I am developing a Add-ins button that do a upstream trace in a network , it works correctly without any error but it does not highlight the traced elements.

I do not know how to highlight the traced elements? thanks in advance

 

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

using ESRI.ArcGIS.esriSystem;

using ESRI.ArcGIS.Carto;

using ESRI.ArcGIS.Editor;

using ESRI.ArcGIS.EditorExt;

using ESRI.ArcGIS.Geodatabase;

using ESRI.ArcGIS.Geometry;

using System.Windows.Forms;

using ESRI.ArcGIS.NetworkAnalysis;

 

namespace testNet

{

    public class testNet : ESRI.ArcGIS.Desktop.AddIns.Button

    {

        private IUtilityNetworkAnalysisExt m_utilNetExt;         

 

        public testNet()

        {

            UID uidUtilNet = new UIDClass();

            uidUtilNet.Value = "esriEditorExt.UtilityNetworkAnalysisExt";

            m_utilNetExt = ArcMap.Application.FindExtensionByCLSID(uidUtilNet) as IUtilityNetworkAnalysisExt;

           

        }

        protected override void OnClick()

        {

             try

            {         

                                         

            INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt;

                 ITraceTasks pTraceTasks = nax as  ITraceTasks;

                 INetwork net = nax.CurrentNetwork.Network;                

              

                 ITraceFlowSolverGEN tfs = new TraceFlowSolverClass() as ITraceFlowSolverGEN;

                 INetSolver netSolver = tfs as INetSolver;

                 netSolver.SourceNetwork = net;

 

                 INetworkAnalysisExtBarriers naxBarriers = m_utilNetExt as INetworkAnalysisExtBarriers;

                 INetElementBarriers juncElemBarriers, edgeElemBarriers;

                 naxBarriers.CreateElementBarriers(out juncElemBarriers, out edgeElemBarriers);

                 ISelectionSetBarriers selSetBarriers;

                 naxBarriers.CreateSelectionBarriers(out selSetBarriers);

                 netSolver.set_ElementBarriers(esriElementType.esriETJunction, juncElemBarriers);

                 netSolver.set_ElementBarriers(esriElementType.esriETEdge, edgeElemBarriers);

                 netSolver.SelectionSetBarriers = selSetBarriers;

                 INetworkAnalysisExtFlags naxFlags = m_utilNetExt as INetworkAnalysisExtFlags;

                

                 int edgeFlagCount = naxFlags.EdgeFlagCount;

                 if (edgeFlagCount > 0)

                 {

                     IEdgeFlag[] edgeFlags = new IEdgeFlag[edgeFlagCount];

                     for (int i = 0; i < edgeFlagCount; i++)

                     {

                         IEdgeFlagDisplay edgeFlagDisplay = naxFlags.get_EdgeFlag(i);

                         IFlagDisplay flagDisplay = edgeFlagDisplay as IFlagDisplay;

                         IEdgeFlag edgeFlag = new EdgeFlagClass();

                         edgeFlag.Position = Convert.ToSingle(edgeFlagDisplay.Percentage);

                         INetFlag netFlag = edgeFlag as INetFlag;

                         netFlag.UserClassID = flagDisplay.FeatureClassID;

                         netFlag.UserID = flagDisplay.FID;

                         netFlag.UserSubID = flagDisplay.SubID;

                         edgeFlags[i] = edgeFlag;

                     }

                     tfs.PutEdgeOrigins(ref edgeFlags);

                 }

                 

                 ITraceTasks traceTasks = m_utilNetExt as ITraceTasks;

                 tfs.TraceIndeterminateFlow = traceTasks.TraceIndeterminateFlow;

 

                 IEnumNetEID resultJuncs, resultEdges;

 

                 esriFlowElements flowElements = traceTasks.TraceFlowElements;

 

                 if (traceTasks.TraceEnds)

                     

                     tfs.FindFlowEndElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges);

                 else

                     

                     tfs.FindFlowElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges);

                                        

            }

             catch (System.Exception excep)

             {

                 MessageBox.Show(excep.Message);

             }

        }    

         protected override void OnUpdate()

        {

           

        }

    }

 

 

}

Outcomes