1

I want to write C# code for utility network analyst (downstream trace task).

My code is:

IUtilityNetworkAnalysisExt m_utilNetExt = new UtilityNetworkAnalysisExtClass();
ITraceFlowSolverGEN tfs = (ITraceFlowSolverGEN)new TraceFlowSolverClass();
IGeometricNetwork pGNetwork = frmNetwork.pGeometricNetwork;
INetworkAnalysisExt nax = (INetworkAnalysisExt)m_utilNetExt;
INetwork net = pGNetwork.Network;
INetSolver netSolver = (INetSolver)tfs;
netSolver.SourceNetwork = net;
INetworkAnalysisExtFlags naxFlags = (INetworkAnalysisExtFlags)m_utilNetExt;

#region set Flag display from feature select
IJunctionFlagDisplay junctionFlagDisplay = new JunctionFlagDisplayClass();
IEdgeFlagDisplay edgeFlagDisplay = new EdgeFlagDisplayClass();
IFlagDisplay flagDisplay;
IEdgeFlag edgeFlag=new EdgeFlagClass();
IJunctionFlag junctionFlag = new JunctionFlagClass();
INetFlag netFlag;
IEdgeFlag[] edgeFlags = new IEdgeFlag[1];
IJunctionFlag[] junctionFlags = new IJunctionFlag[1];

if (pFeature != null && pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
{
    flagDisplay = (IFlagDisplay)edgeFlagDisplay;
    flagDisplay.FeatureClassID = pFLayer.FeatureClass.FeatureClassID;
    flagDisplay.FID = pFeature.OID;
    flagDisplay.SubID = -1;
    edgeFlagDisplay =(IEdgeFlagDisplay) flagDisplay;
    edgeFlag.Position = Convert.ToSingle(edgeFlagDisplay.Percentage);
    netFlag =(INetFlag) edgeFlag;
    netFlag.UserClassID = flagDisplay.FeatureClassID;
    netFlag.UserID = flagDisplay.FID;
    netFlag.UserSubID = flagDisplay.SubID;                    
    edgeFlags[0] = edgeFlag;
    tfs.PutEdgeOrigins(ref edgeFlags);
}

if (pFeature != null && pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
{
    flagDisplay = (IFlagDisplay)junctionFlagDisplay;
    flagDisplay.FeatureClassID = pFLayer.FeatureClass.FeatureClassID;
    flagDisplay.FID = pFeature.OID;
    flagDisplay.SubID = -1;
    junctionFlagDisplay = (IJunctionFlagDisplay)flagDisplay;
    //junctionFlag.Position = Convert.ToSingle(junctionFlagDisplay.Percentage);
    netFlag = (INetFlag)junctionFlag;
    netFlag.UserClassID = flagDisplay.FeatureClassID;
    netFlag.UserID = flagDisplay.FID;
    netFlag.UserSubID = flagDisplay.SubID;
    junctionFlags[0] = junctionFlag;
    tfs.PutJunctionOrigins(ref junctionFlags);

}

ITraceTasks traceTasks =(ITraceTasks) m_utilNetExt;
tfs.TraceIndeterminateFlow = traceTasks.TraceIndeterminateFlow;
IEnumNetEID resultJuncs, resultEdges;
esriFlowElements flowelements = traceTasks.TraceFlowElements;
tfs.FindFlowElements(esriFlowMethod.esriFMUpstream, flowelements, out resultJuncs, out resultEdges);

INetworkAnalysisExtResults naxResults =(INetworkAnalysisExtResults) m_utilNetExt;
naxResults.ClearResults();
naxResults.CreateSelection(resultJuncs, resultEdges);

#endregion

This code does not work, please help me?

  • You might get a better response if you actually say what the error was... Also consider posting on the ESRI forum as this is likely to be a very technical reponse. – Hornbydd Sep 1 '14 at 11:09