/// <summary> /// This routine takes a row from the starting (or barrier) point table and converts it to a [Network] Element that we can use for tracing /// </summary> /// <param name="pointRow">The Row (either starting point or barrier point)</param> /// <param name="utilityNetwork">Utility Network to be used</param> /// <param name="definition">Utility Network definition to be used</param> /// <returns>newly created element</returns> private static Element GetElementFromPointRow(Row pointRow, UtilityNetwork utilityNetwork, UtilityNetworkDefinition definition) { // Fetch the SourceID, AssetGroupCode, AssetType, GlobalID, and TerminalID values from the starting point row int sourceID = (int)pointRow[PointsSourceIDFieldName]; int assetGroupID = (int)pointRow[PointsAssetGroupFieldName]; int assetTypeID = (int)pointRow[PointsAssetTypeFieldName]; Guid globalID = new Guid(pointRow[PointsGlobalIDFieldName].ToString()); int terminalID = (int)pointRow[PointsTerminalFieldName]; double percentAlong = (double)pointRow[PointsPercentAlong]; // Fetch the NetworkSource, AssetGroup, and AssetType objects NetworkSource networkSource = definition.GetNetworkSources().First(x => x.ID == sourceID); AssetGroup assetGroup = networkSource.GetAssetGroups().First(x => x.Code == assetGroupID); AssetType assetType = assetGroup.GetAssetTypes().First(x => x.Code == assetTypeID); // Fetch the Terminal object from the ID Terminal terminal = null; if (assetType.IsTerminalConfigurationSupported()) { TerminalConfiguration terminalConfiguration = assetType.GetTerminalConfiguration(); terminal = terminalConfiguration.Terminals.First(x => x.ID == terminalID); } // Create and return a FeatureElement object // If we have an edge, set the PercentAlongEdge property; otherwise set the Terminal property if (networkSource.Type == SourceType.Edge) { Element element = utilityNetwork.CreateElement(assetType, globalID); element.PercentAlongEdge = percentAlong; return(element); } else { Element element = utilityNetwork.CreateElement(assetType, globalID, terminal); return(element); } }
/// <summary> /// GetNetworkElementFromStartingPoint /// /// This routine takes a row from the starting point table and converts it to a NetworkElement that we can use for tracing /// /// </summary> /// private Element GetElementFromStartingPointRow(Row startingPointRow, UtilityNetwork utilityNetwork, UtilityNetworkDefinition definition) { // Fetch the SourceID, AssetGroupCode, AssetType, GlobalID, and TerminalID values from the starting point row object vSourceID = startingPointRow[StartingPointsSourceIDFieldName]; int sourceID = (int)vSourceID; object vAssetGroupID = startingPointRow[StartingPointsAssetGroupFieldName]; int assetGroupID = (int)vAssetGroupID; object vAssetTypeID = startingPointRow[StartingPointsAssetTypeFieldName]; int assetTypeID = (int)vAssetTypeID; object vGlobalID = startingPointRow[StartingPointsGlobalIDFieldName]; Guid globalID = new Guid(vGlobalID.ToString()); object vTerminalID = startingPointRow[StartingPointsTerminalFieldName]; int terminalID = (int)vTerminalID; // Fetch the NetworkSource, AssetGroup, and AssetType objects NetworkSource networkSource = definition.GetNetworkSources().First(x => x.ID == sourceID); AssetGroup assetGroup = networkSource.GetAssetGroups().First(x => x.Code == assetGroupID); AssetType assetType = assetGroup.GetAssetTypes().First(x => x.Code == assetTypeID); // Fetch the Terminal object from the ID Terminal terminal = null; if (assetType.IsTerminalConfigurationSupported()) { TerminalConfiguration terminalConfiguration = assetType.GetTerminalConfiguration(); terminal = terminalConfiguration.Terminals.First(x => x.ID == terminalID); } // Create and return a Element object return(utilityNetwork.CreateElement(assetType, globalID, terminal)); }
private static void ExecuteTrace(Guid traceStartGuid, string geodatabasePath) { using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(geodatabasePath)))) { IReadOnlyList <UtilityNetworkDefinition> utilityNetworkDefinitions = geodatabase.GetDefinitions <UtilityNetworkDefinition>(); string utilityNetworkName = string.Empty; if (utilityNetworkDefinitions.Count < 0 || utilityNetworkDefinitions.Count > 1) { return; } // Get utility network name from the dataset foreach (UtilityNetworkDefinition definition in utilityNetworkDefinitions) { utilityNetworkName = definition.GetName(); Console.WriteLine($"Utility network name: {utilityNetworkName}"); definition.Dispose(); } // Open utility network using (UtilityNetwork utilityNetwork = geodatabase.OpenDataset <UtilityNetwork>(utilityNetworkName)) using (UtilityNetworkDefinition utilityNetworkDefinition = utilityNetwork.GetDefinition()) { using (NetworkSource networkSource = utilityNetworkDefinition.GetNetworkSource("ElectricDevice")) using (AssetGroup assetGroup = networkSource.GetAssetGroup("Medium Voltage Transformer")) using (AssetType assetType = assetGroup.GetAssetType("Overhead Single Phase")) { DomainNetwork domainNetwork = utilityNetworkDefinition.GetDomainNetwork("Electric"); Tier sourceTier = domainNetwork.GetTier("Electric Distribution"); TraceConfiguration traceConfiguration = sourceTier.GetTraceConfiguration(); // Get downstream side of the terminal Terminal terminal = null; if (assetType.IsTerminalConfigurationSupported()) { TerminalConfiguration terminalConfiguration = assetType.GetTerminalConfiguration(); IReadOnlyList <Terminal> terminals = terminalConfiguration.Terminals; terminal = terminals.First(t => !t.IsUpstreamTerminal); } // Create an element to begin a trace Element startingPointElement = utilityNetwork.CreateElement(assetType, traceStartGuid, terminal); List <Element> startingPoints = new List <Element>(); startingPoints.Add(startingPointElement); // Get trace manager using (TraceManager traceManager = utilityNetwork.GetTraceManager()) { // Set trace configurations TraceArgument traceArgument = new TraceArgument(startingPoints); traceArgument.Configuration = traceConfiguration; // Get downstream tracer Tracer tracer = traceManager.GetTracer <DownstreamTracer>(); // Execuate downstream trace IReadOnlyList <Result> traceResults = tracer.Trace(traceArgument); // Display trace results in console foreach (Result result in traceResults) { if (result is ElementResult) { ElementResult elementResult = result as ElementResult; IReadOnlyList <Element> elements = elementResult.Elements; Console.WriteLine("Trace result elements:"); foreach (Element element in elements) { Console.WriteLine($"\t OID: {element.ObjectID}, Name:{element.AssetType.Name}"); } } else if (result is FunctionOutputResult) { FunctionOutputResult functionResult = result as FunctionOutputResult; IReadOnlyList <FunctionOutput> functionOutputs = functionResult.FunctionOutputs; Console.WriteLine("Trace result function outputs:"); foreach (FunctionOutput functionOut in functionOutputs) { Console.WriteLine($"\t Function result:{functionOut.Value}, name: {functionOut.Function}"); } } else if (result is AggregatedGeometryResult) { AggregatedGeometryResult aggResults = result as AggregatedGeometryResult; Polyline aggregatedLine = aggResults.Line as Polyline; Multipoint aggregatedPoint = aggResults.Point as Multipoint; Polygon aggregatedPolygon = aggResults.Polygon as Polygon; } } } } } } }