public static string TracePath(double[] Xs, double[] Ys, string GeoNetName, IApplication app, IMap map, bool traceIndeterminate,
double snapTol, bool selectEdges, out IEnumNetEID juncEIDs, out IEnumNetEID edgeEIDs, out IGeometricNetwork gn)
{
gn = null;
juncEIDs = null;
edgeEIDs = null;
List<INetFlag> pNetFlags = null;
IFlagDisplay pFlagDisplay = null;
IJunctionFlag[] junctionFlags = null;
IEdgeFlag[] edgeFlags = null;
ITraceFlowSolverGEN traceFlowSolver = null;
List<IEdgeFlag> pEdgeFlags = null;
List<IJunctionFlag> pJunctionFlags = null;
INetElementBarriers pEdgeElementBarriers;
INetElementBarriers pJunctionElementBarriers;
ISelectionSetBarriers pSelectionSetBarriers;
List<IGeometricNetwork> gnList = null;
INetworkAnalysisExt pNetAnalysisExt = null;
UID pID = null;
try
{
gnList = Globals.GetGeometricNetworks(ref map);
if (gnList == null)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_17a"));
return "";
}
int gnIdx = -1;
gnIdx = Globals.GetGeometricNetwork(ref gnList, GeoNetName);
if (gnIdx != -1)
{
gn = (IGeometricNetwork)gnList[gnIdx];
}
pNetFlags = new List<INetFlag>();
// INetFlag[] netFlags = new INetFlag[Xs.Length];
for (int i = 0; i < Xs.Length; i++)
{
IPoint snappedPoint = null; int EID = -1;
if (gn == null)
{
pNetFlags.Add(Globals.GetJunctionFlag(Xs[i], Ys[i], ref map, ref gnList, snapTol, ref gnIdx,
out snappedPoint, out EID, out pFlagDisplay, true) as INetFlag);
//Set network to trace
if (gnIdx > -1)
gn = gnList[gnIdx] as IGeometricNetwork;
}
else
{
pNetFlags.Add(Globals.GetJunctionFlagWithGN(Xs[i], Ys[i], ref map, ref gn, ref snapTol, out snappedPoint, out EID, out pFlagDisplay, true) as INetFlag);
}
}
if (gn == null || pNetFlags.Count < 1)
{
return (A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_17b"));
}
if (app != null)
{
pID = new UID();
pID.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
pNetAnalysisExt = (INetworkAnalysisExt)app.FindExtensionByCLSID(pID);
Globals.SetCurrentNetwork(ref pNetAnalysisExt, ref gn);
traceFlowSolver = Globals.CreateTraceFlowSolverFromToolbar(ref pNetAnalysisExt, out pEdgeFlags, out pJunctionFlags, out pEdgeElementBarriers, out pJunctionElementBarriers, out pSelectionSetBarriers) as ITraceFlowSolverGEN;
}
else
{
traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;
INetSolver netSolver = traceFlowSolver as INetSolver;
netSolver.SourceNetwork = gn.Network;
}
traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate;
if (pEdgeFlags != null)
{
foreach (IEdgeFlag pEdFl in pEdgeFlags)
{
pNetFlags.Add((INetFlag)pEdFl);
}
}
if (pJunctionFlags != null)
{
foreach (IJunctionFlag pJcFl in pJunctionFlags)
{
pNetFlags.Add((INetFlag)pJcFl);
}
}
//if (startNetFlag != null)
//{
// pNetFlags.Add((INetFlag)startNetFlag);
//}
Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlags, out edgeFlags);
int intCount = 1;
System.Object[] segCosts = new System.Object[1];
segCosts[0] = new System.Object();
traceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinMax,
out juncEIDs, out edgeEIDs, intCount, ref segCosts);
//Select junction features
map.ClearSelection();
IJunctionFlag[] junctionFlag = null;
Globals.SelectJunctions(ref map, ref gn, ref juncEIDs, ref junctionFlag, "", "", "", true);
if (selectEdges)
Globals.SelectEdges(ref map, ref gn, ref edgeEIDs);
edgeEIDs.Reset();
//Draw edge graphics
IEnvelope env = Globals.DrawEdges(ref map, ref gn, ref edgeEIDs);
return edgeEIDs.Count.ToString();
}
catch (Exception Ex)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_17a") + "\n" + Ex.Message);
return "";
}
}