公共设施网络

获取公共设施网络

从表中获取公共设施网络

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public static UtilityNetwork GetUtilityNetworkFromTable(Table table)
{
UtilityNetwork utilityNetwork = null;

if (table.IsControllerDatasetSupported())
{
// Tables can belong to multiple controller datasets, but at most one of them will be a UtilityNetwork
IReadOnlyList<Dataset> controllerDatasets = table.GetControllerDatasets();

foreach (Dataset controllerDataset in controllerDatasets)
{
if (controllerDataset is UtilityNetwork)
{
utilityNetwork = controllerDataset as UtilityNetwork;
}
else
{
controllerDataset.Dispose();
}
}
}
return utilityNetwork;
}

从图层获取公共设施网络

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// This routine obtains a utility network from a FeatureLayer, SubtypeGroupLayer, or UtilityNetworkLayer
public static UtilityNetwork GetUtilityNetworkFromLayer(Layer layer)
{
UtilityNetwork utilityNetwork = null;

if (layer is UtilityNetworkLayer)
{
UtilityNetworkLayer utilityNetworkLayer = layer as UtilityNetworkLayer;
utilityNetwork = utilityNetworkLayer.GetUtilityNetwork();
}

else if (layer is SubtypeGroupLayer)
{
CompositeLayer compositeLayer = layer as CompositeLayer;
utilityNetwork = GetUtilityNetworkFromLayer(compositeLayer.Layers.First());
}

else if (layer is FeatureLayer)
{
FeatureLayer featureLayer = layer as FeatureLayer;
using (FeatureClass featureClass = featureLayer.GetFeatureClass())
{
if (featureClass.IsControllerDatasetSupported())
{
IReadOnlyList<Dataset> controllerDatasets = new List<Dataset>();
controllerDatasets = featureClass.GetControllerDatasets();
foreach (Dataset controllerDataset in controllerDatasets)
{
if (controllerDataset is UtilityNetwork)
{
utilityNetwork = controllerDataset as UtilityNetwork;
}
else
{
controllerDataset.Dispose();
}
}
}
}
}
return utilityNetwork;
}

元素

从元素中获取行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// usage :   using (var row = FetchRowFromElement(...))
public static Row FetchRowFromElement(UtilityNetwork utilityNetwork, Element element)
{
// Get the table from the element
using (Table table = utilityNetwork.GetTable(element.NetworkSource))
{
// Create a query filter to fetch the appropriate row
QueryFilter queryFilter = new QueryFilter()
{
ObjectIDs = new List<long>() { element.ObjectID }
};

// Fetch and return the row
using (RowCursor rowCursor = table.Search(queryFilter))
{
if (rowCursor.MoveNext())
{
return rowCursor.Current;
}
return null;
}
}
}

编辑关联

创建公共设施网络关联

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Create edit operation
EditOperation editOperation = new EditOperation();
editOperation.Name = "Create structural attachment association";

// Create a RowHandle for the pole

Element poleElement = utilityNetwork.CreateElement(poleAssetType, poleGlobalID);
RowHandle poleRowHandle = new RowHandle(poleElement, utilityNetwork);

// Create a RowHandle for the transformer bank

Element transformerBankElement = utilityNetwork.CreateElement(transformerBankAssetType, transformerBankGlobalID);
RowHandle transformerBankRowHandle = new RowHandle(transformerBankElement, utilityNetwork);

// Attach the transformer bank to the pole

AssociationDescription structuralAttachmentAssociationDescription = new AssociationDescription(AssociationType.Attachment, poleRowHandle, transformerBankRowHandle);
editOperation.Create(structuralAttachmentAssociationDescription);
editOperation.Execute();

在单个编辑操作中创建公共设施网络要素和关联

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Create an EditOperation
EditOperation editOperation = new EditOperation();
editOperation.Name = "Create pole; create transformer bank; attach transformer bank to pole";

// Create the transformer bank
RowToken transformerBankToken = editOperation.Create(transformerBankLayer, transformerBankAttributes);

// Create a pole
RowToken poleToken = editOperation.Create(poleLayer, poleAttributes);

// Create a structural attachment association between the pole and the transformer bank
RowHandle poleHandle = new RowHandle(poleToken);
RowHandle transformerBankHandle = new RowHandle(transformerBankToken);

AssociationDescription poleAttachment = new AssociationDescription(AssociationType.Attachment, poleHandle, transformerBankHandle);

editOperation.Create(poleAttachment);

// Execute the EditOperation
editOperation.Execute();

遍历关联

获取向下遍历产生的遍历关联

1
2
3
4
5
6
7
8
9
10
11
public static void GetTraverseAssociationsResultFromDownwardTraversal(UtilityNetwork utilityNetwork, IReadOnlyList<Element> startingElements)
{
// Set downward traversal with maximum depth
TraverseAssociationsDescription traverseAssociationsDescription = new TraverseAssociationsDescription(TraversalDirection.Descending);

// Get traverse associations result from the staring element up to maximum depth
TraverseAssociationsResult traverseAssociationsResult = utilityNetwork.TraverseAssociations(startingElements, traverseAssociationsDescription);

// Get associations participated in traversal
IReadOnlyList<Association> associations = traverseAssociationsResult.Associations;
}

获取具有深度限制的向上遍历产生的遍历关联

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public static void GetTraverseAssociationsResultFromUpwardTraversalWithDepthLimit(UtilityNetwork utilityNetwork, IReadOnlyList<Element> startingElements)
{
// List of fields whose values will be fetched as name-values pairs during association traversal operation
List<string> additionalFieldsToFetch = new List<string> { "ObjectId", "AssetName", "AssetGroup", "AssetType" };

// Set downward traversal with maximum depth level of 3
TraverseAssociationsDescription traverseAssociationsDescription = new TraverseAssociationsDescription(TraversalDirection.Ascending, 3)
{
AdditionalFields = additionalFieldsToFetch
};

// Get traverse associations result from the staring element up to depth level 3
TraverseAssociationsResult traverseAssociationsResult = utilityNetwork.TraverseAssociations(startingElements, traverseAssociationsDescription);

// List of associations participated in traversal
IReadOnlyList<Association> associations = traverseAssociationsResult.Associations;

// KeyValue mapping between involved elements and their field name-values
//At 2.x - IReadOnlyDictionary<Element, IReadOnlyList<AssociationElementFieldValue>> associationElementValuePairs = traverseAssociationsResult.AdditionalFieldValues;
IReadOnlyDictionary<Element, IReadOnlyList<FieldValue>> associationElementValuePairs =
traverseAssociationsResult.AdditionalFieldValues;

foreach (KeyValuePair<Element, IReadOnlyList<FieldValue>> keyValuePair in associationElementValuePairs)
{
// Element
Element element = keyValuePair.Key;

// List of field names and their values
//At 2.x - IReadOnlyList<AssociationElementFieldValue> elementFieldValues = keyValuePair.Value;
IReadOnlyList<FieldValue> elementFieldValues = keyValuePair.Value;
}
}

子网和层

查找给定域网络名称和层名称的层

1
2
3
4
5
using (UtilityNetworkDefinition utilityNetworkDefinition = utilityNetwork.GetDefinition())
{
DomainNetwork domainNetwork = utilityNetworkDefinition.GetDomainNetwork(domainNetworkName);
Tier tier = domainNetwork.GetTier(tierName);
}

更新层中的所有脏子网

1
2
3
4
5
6
using (SubnetworkManager subnetworkManager = utilityNetwork.GetSubnetworkManager())
{
subnetworkManager.UpdateAllSubnetworks(tier, true);

mapView.Redraw(true);
}

具有一个控制器的简单径向子网的生命周期

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Create a subnetwork named "Radial1" with a single controller
// elementR1 represents the device that serves as the subnetwork controller (e.g., circuit breaker)
Subnetwork subnetworkRadial1 = subnetworkManager.EnableControllerInEditOperation(mediumVoltageTier, elementR1, "Radial1", "R1", "my description", "my notes");

// ...

// Update the subnetwork and refresh the map
subnetworkRadial1.Update();
MapView.Active.Redraw(true);

// ...

// At some point, a subnetwork will need to be deleted.

// First step is to disable the controller
subnetworkManager.DisableControllerInEditOperation(elementR1);

// At this point, the subnetwork is deleted, but all of the rows that have been labeled with the subnetwork ID need to be updated
subnetworkRadial1.Update();
MapView.Active.Redraw(true);

// The final step is to notify external systems (if any) using the Export Subnetwork geoprocessing tool

具有多个控制器的网格子网的生命周期

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Create a subnetwork named "Mesh1" from three controllers
// elementM1, elementM2, and elementM3 represent the devices that serve as subnetwork controllers (e.g., network protectors)
subnetworkManager.EnableController(lowVoltageMeshTier, elementM1, "Mesh1", "M1", "my description", "my notes");
subnetworkManager.EnableController(lowVoltageMeshTier, elementM2, "Mesh1", "M2", "my description", "my notes");
Subnetwork subnetworkMesh1 = subnetworkManager.EnableController(lowVoltageMeshTier, elementM3, "Mesh1", "M3", "my description", "my notes");
subnetworkMesh1.Update();
MapView.Active.Redraw(true);

// ...

// When deleting the subnetwork, each controller must be disabled before the subnetwork itself is deleted
subnetworkManager.DisableControllerInEditOperation(elementM1);
subnetworkManager.DisableControllerInEditOperation(elementM2);
subnetworkManager.DisableControllerInEditOperation(elementM3);

// After the subnetwork is deleted, all of the rows that have been labeled with the subnetwork ID need to be updated
subnetworkMesh1.Update();
MapView.Active.Redraw(true);

// The final step is to notify external systems (if any) using the Export Subnetwork geoprocessing tool

具有两个控制器的重馈径向子网的生命周期

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Create a subnetwork named "R2, R3" from two controllers
// elementR2 and elementR3 represent the devices that serve as subnetwork controllers (e.g., circuit breakers)
subnetworkManager.EnableControllerInEditOperation(mediumVoltageTier, elementR2, "R2, R3", "R2", "my description", "my notes");
subnetworkManager.EnableControllerInEditOperation(mediumVoltageTier, elementR3, "R2, R3", "R3", "my description", "my notes");

// If the tie switch between them is opened, the original subnetwork controllers must be disabled and re-enabled with different names
// This will create two new subnetworks, named "R2" and "R3"
subnetworkManager.DisableControllerInEditOperation(elementR2);
subnetworkManager.DisableControllerInEditOperation(elementR3);

Subnetwork subnetworkR2 = subnetworkManager.EnableControllerInEditOperation(mediumVoltageTier, elementR2, "R2", "R2", "my description", "my notes");
Subnetwork subnetworkR3 = subnetworkManager.EnableControllerInEditOperation(mediumVoltageTier, elementR3, "R3", "R3", "my description", "my notes");

subnetworkR2.Update();
subnetworkR3.Update();
MapView.Active.Redraw(true);

描图

创建下游跟踪程序

1
2
3
4
using (TraceManager traceManager = utilityNetwork.GetTraceManager())
{
DownstreamTracer downstreamTracer = traceManager.GetTracer<DownstreamTracer>();
}

创建跟踪参数

1
2
3
4
5
6
7
8
9
IReadOnlyList<Element> startingPointList = new List<Element>();

// Code to fill in list of starting points goes here...
TraceArgument traceArgument = new TraceArgument(startingPointList);

TraceConfiguration traceConfiguration = new TraceConfiguration();

// Code to fill in trace configuration goes here...
traceArgument.Configuration = traceConfiguration;

创建条件以将网络属性与一组值进行比较

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Create a NetworkAttribute object for the Lifecycle network attribute from the UtilityNetworkDefinition
using (NetworkAttribute lifecycleNetworkAttribute = utilityNetworkDefinition.GetNetworkAttribute("Lifecycle"))
{
// Create a NetworkAttributeComparison that stops traversal if Lifecycle <> "In Design" (represented by the constant InDesign)
NetworkAttributeComparison inDesignNetworkAttributeComparison = new NetworkAttributeComparison(lifecycleNetworkAttribute, Operator.NotEqual, InDesign);

// Create a NetworkAttributeComparison to stop traversal if Lifecycle <> "In Service" (represented by the constant InService)
NetworkAttributeComparison inServiceNetworkAttributeComparison = new NetworkAttributeComparison(lifecycleNetworkAttribute, Operator.NotEqual, InService);

// Combine these two comparisons together with "And"
And lifecycleFilter = new And(inDesignNetworkAttributeComparison, inServiceNetworkAttributeComparison);

// Final condition stops traversal if Lifecycle <> "In Design" and Lifecycle <> "In Service"
traceConfiguration.Traversability.Barriers = lifecycleFilter;
}

创建函数

1
2
3
4
5
6
7
8
9
// Get a NetworkAttribute object for the Load network attribute from the UtilityNetworkDefinition
using (NetworkAttribute loadNetworkAttribute = utilityNetworkDefinition.GetNetworkAttribute("Load"))
{
// Create a function to sum the Load
Add sumLoadFunction = new Add(loadNetworkAttribute);

// Add this function to our trace configuration
traceConfiguration.Functions = new List<Function>() { sumLoadFunction };
}

创建功能屏障

1
2
3
4
5
6
7
8
9
10
11
12
// Create a NetworkAttribute object for the Shape length network attribute from the UtilityNetworkDefinition
using (NetworkAttribute shapeLengthNetworkAttribute = utilityNetworkDefinition.GetNetworkAttribute("Shape length"))
{
// Create a function that adds up shape length
Add lengthFunction = new Add(shapeLengthNetworkAttribute);

// Create a function barrier that stops traversal after 1000 feet
FunctionBarrier distanceBarrier = new FunctionBarrier(lengthFunction, Operator.GreaterThan, 1000.0);

// Set this function barrier
traceConfiguration.Traversability.FunctionBarriers = new List<FunctionBarrier>() { distanceBarrier };
}

创建输出条件

1
2
3
// Create an output category to filter the trace results to only include
// features with the "Service Point" category assigned
traceConfiguration.OutputCondition = new CategoryComparison(CategoryOperator.IsEqual, "Service Point");

创建传播器

1
2
3
4
5
6
7
8
9
10
11
// Get a NetworkAttribute object for the Phases Normal attribute from the UtilityNetworkDefinition
using (NetworkAttribute normalPhaseAttribute = utilityNetworkDefinition.GetNetworkAttribute("Phases Normal"))
{
// Create a propagator to propagate the Phases Normal attribute downstream from the source, using a Bitwise And function
// Allow traversal to continue as long as the Phases Normal value includes any of the ABC phases
// (represented by the constant ABCPhase)
Propagator phasePropagator = new Propagator(normalPhaseAttribute, PropagatorFunction.BitwiseAnd, Operator.IncludesAny, ABCPhase);

// Assign this propagator to our trace configuration
traceConfiguration.Propagators = new List<Propagator>() { phasePropagator };
}

使用函数结果

1
2
3
4
5
6
7
8
9
// Get the FunctionOutputResult from the trace results
FunctionOutputResult functionOutputResult = traceResults.OfType<FunctionOutputResult>().First();

// First() can be used here if only one Function was included in the TraceConfiguration.Functions collection.
// Otherwise you will have to search the list for the correct FunctionOutput object.
FunctionOutput functionOutput = functionOutputResult.FunctionOutputs.First();

// Extract the total load from the GlobalValue property
double totalLoad = (double)functionOutput.Value;

按名称获取命名跟踪配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private void GetNamedTraceConfigurationsByName(UtilityNetwork utilityNetwork, string configurationName)
{
// Query to find named trace configurations
NamedTraceConfigurationQuery namedTraceConfigurationQuery = new NamedTraceConfigurationQuery { Names = new List<string> { configurationName } };

// Get the trace manager from the utility network
using (TraceManager traceManager = utilityNetwork.GetTraceManager())
{
// A set of named trace configurations specified by the named traced configuration query
IReadOnlyList<NamedTraceConfiguration> namedTraceConfigurations = traceManager.GetNamedTraceConfigurations(namedTraceConfigurationQuery);

foreach (NamedTraceConfiguration namedTraceConfiguration in namedTraceConfigurations)
{
// Use NamedTraceConfiguration's object
}
}
}

从公共设施网络图层获取指定追踪配置

1
2
3
4
5
6
7
8
9
10
private void GetNamedTraceConfigurationsFromUtilityNetworkLayer(UtilityNetworkLayer utilityNetworkLayer)
{
// Get all named trace configurations in the utility network
IReadOnlyList<NamedTraceConfiguration> namedTraceConfigurations = utilityNetworkLayer.GetNamedTraceConfigurations();

foreach (NamedTraceConfiguration namedTraceConfiguration in namedTraceConfigurations)
{
// Use NamedTraceConfiguration's object
}
}

使用指定追踪配置追踪公共设施网络

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private void TraceUtilityNetworkUsingNamedTraceConfiguration(UtilityNetwork utilityNetwork, NamedTraceConfiguration namedTraceConfiguration, Element startElement)
{
// Get the trace manager from the utility network
using (TraceManager traceManager = utilityNetwork.GetTraceManager())
{
// Get a tracer from the trace manager using the named trace configuration
Tracer upstreamTracer = traceManager.GetTracer(namedTraceConfiguration);

// Trace argument holding the trace input parameters
TraceArgument upstreamTraceArgument = new TraceArgument(namedTraceConfiguration, new List<Element> {startElement});

// Trace results
IReadOnlyList<Result> upstreamTraceResults = upstreamTracer.Trace(upstreamTraceArgument);
}
}

网络图

获取图管理器

1
2
3
4
using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
{
// Todo - do something
}

获取网络图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
{
// get all the diagrams
IReadOnlyList<NetworkDiagram> diagrams = diagramManager.GetNetworkDiagrams();

// get a diagram by name
NetworkDiagram diagram = diagramManager.GetNetworkDiagram(diagrameName);

// get diagrams by extent
diagrams = diagramManager.GetNetworkDiagrams(extentOfInterest);

// get diagrams from a set of utility network feature GlobalIDs
diagrams = diagramManager.GetNetworkDiagrams(globalIDs);

// get diagrams from a set of utility network feature GlobalIDs within an extent
diagrams = diagramManager.GetNetworkDiagrams(extentOfInterest, globalIDs);
}

获取具有不一致一致性状态的网络图列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public List<NetworkDiagram> GetInconsistentDiagrams(UtilityNetwork utilityNetwork)
{
// Get the DiagramManager from the utility network

using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
{
List<NetworkDiagram> myList = new List<NetworkDiagram>();

// Loop through the network diagrams in the diagram manager

foreach (NetworkDiagram diagram in diagramManager.GetNetworkDiagrams())
{
NetworkDiagramInfo diagramInfo = diagram.GetDiagramInfo();

// If the diagram is not a system diagram and is in an inconsistent state, add it to our list

if (!diagramInfo.IsSystem && diagram.GetConsistencyState() != NetworkDiagramConsistencyState.DiagramIsConsistent)
{
myList.Add(diagram);
}
else
{
diagram.Dispose(); // If we are not returning it we need to Dispose it
}
}

return myList;
}
}

从网络逻辑示意图中打开逻辑示意图窗格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Create a diagram layer from a NetworkDiagram (myDiagram)
DiagramLayer diagramLayer = await QueuedTask.Run<DiagramLayer>(() =>
{
// Create the diagram map
var newMap = MapFactory.Instance.CreateMap(myDiagram.Name, ArcGIS.Core.CIM.MapType.NetworkDiagram, MapViewingMode.Map);
if (newMap == null)
return null;

// Open the diagram map
var mapPane = ArcGIS.Desktop.Core.ProApp.Panes.CreateMapPaneAsync(newMap, MapViewingMode.Map);
if (mapPane == null)
return null;

//Add the diagram to the map
return newMap.AddDiagramLayer(myDiagram);
});

从关系图层获取关系图

1
2
3
4
5
6
7
8
9
10
11
12
public void GetDiagram(DiagramLayer diagramLayer)
{
// note - methods need to run on MCT

NetworkDiagram diagram = diagramLayer.GetNetworkDiagram();

// get the consistency state from the layer
DiagramLayerConsistencyState dlState = diagramLayer.ConsistencyState;

// or from the diagram
NetworkDiagramConsistencyState ndState = diagram.GetConsistencyState();
}

获取图表模板

1
2
3
4
5
6
7
8
9
10
11
public void RetrieveDiagramTemplates(UtilityNetwork utilityNetwork)
{
using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
{
// get all templates
IReadOnlyList<DiagramTemplate> templates = diagramManager.GetDiagramTemplates();

// get a template by name
DiagramTemplate template = diagramManager.GetDiagramTemplate(templateName);
}
}

从逻辑示意图模板获取网络逻辑示意图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public void GetNetworkDiagramFromDiagramTemplates(UtilityNetwork utilityNetwork)
{
using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
{
// get the first templates
DiagramTemplate template = diagramManager.GetDiagramTemplates().FirstOrDefault();

// get the network diagrams fromt he template
IEnumerable<NetworkDiagram> diagrams = template.GetNetworkDiagrams();

// or get a network diagram by name
NetworkDiagram diagram = template.GetNetworkDiagram(diagrameName);
}
}

创建网络图

1
2
3
4
5
6
7
8
9
10
11
public void CreateNetworkDiagram(UtilityNetwork utilityNetwork, IEnumerable<Guid> globalIDs)
{
using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
{
// get the template
DiagramTemplate template = diagramManager.GetDiagramTemplate(templateName);

// create the diagram
NetworkDiagram diagram = diagramManager.CreateNetworkDiagram(template, globalIDs);
}
}

以 JSON 字符串形式获取网络逻辑示意图信息

1
2
3
4
5
6
7
8
9
10
public void GetDiagramContent(UtilityNetwork utilityNetwork)
{
using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
{
// get a diagram by name
NetworkDiagram diagram = diagramManager.GetNetworkDiagram(templateName);

string json_content = diagram.GetContent(true, true, true, true);
}
}

获取图元素

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public void GetDiagramElements(MapView mapView, NetworkDiagram networkDiagram)
{
// Create a DiagramElementQueryByExtent to retrieve diagram element junctions whose extent
// intersects the active map extent

DiagramElementQueryByExtent elementQuery = new DiagramElementQueryByExtent();
elementQuery.ExtentOfInterest = MapView.Active.Extent;
elementQuery.AddContents = false;
elementQuery.QueryDiagramJunctionElement = true;
elementQuery.QueryDiagramEdgeElement = false;
elementQuery.QueryDiagramContainerElement = false;

// Use this DiagramElementQueryByExtent as an argument to the QueryDiagramElements method
DiagramElementQueryResult result = networkDiagram.QueryDiagramElements(elementQuery);

// get the container, junction, edge elements
// in this case result.DiagramJunctionElements and result.DiagramEdgeElements will be empty
// since elementQuery.QueryDiagramEdgeElement and elementQuery.QueryDiagramContainerElement are set to false
IReadOnlyList<DiagramContainerElement> containerElements = result.DiagramContainerElements;

IReadOnlyList<DiagramJunctionElement> junctionElements = result.DiagramJunctionElements;

IReadOnlyList<DiagramEdgeElement> edgeElements = result.DiagramEdgeElements;
}

获取逻辑示意图聚合

1
2
3
4
5
6
7
8
public void GetDiagramAggregation(NetworkDiagram networkDiagram)
{
IReadOnlyList<DiagramAggregation> aggregations = networkDiagram.GetAggregations();
foreach (var aggregation in aggregations)
{
var type = aggregation.AggregationType;
}
}

查找一组公共设施网络行的逻辑示意图要素

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public void FindDiagramFeatures(NetworkDiagram diagram, List<Guid> globalIDs)
{
FindDiagramFeatureQuery featureQuery = new FindDiagramFeatureQuery();
featureQuery.NetworkRowGlobalIDs = globalIDs;
featureQuery.AddAggregations = true;
featureQuery.AddConnectivityAssociations = true;
featureQuery.AddStructuralAttachments = true;

IReadOnlyList<FindResultItem> features = diagram.FindDiagramFeatures(featureQuery);
foreach (var findFeature in features)
{
long objectID = findFeature.ObjectID;
Guid guid = findFeature.GlobalID;
GeometryType geometryType = findFeature.GeometryType;
int sourceID = findFeature.SourceID;
}
}

查找一组逻辑示意图要素的公共设施网络行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public void FindDiagramRows(NetworkDiagram diagram, List<Guid> globalIDs)
{
FindNetworkRowQuery rowQuery = new FindNetworkRowQuery();
rowQuery.DiagramFeatureGlobalIDs = globalIDs;
rowQuery.AddAggregations = true;

IReadOnlyList<FindResultItem> rows = diagram.FindNetworkRows(rowQuery);
foreach (var findRow in rows)
{
long objectID = findRow.ObjectID;
Guid guid = findRow.GlobalID;
GeometryType geometryType = findRow.GeometryType;
int sourceID = findRow.SourceID;
}
}

查找用于创建网络逻辑示意图的初始网络行

1
2
3
4
5
6
7
8
9
10
11
public void FindInitialNetworkRows(NetworkDiagram diagram)
{
IReadOnlyList<FindResultItem> rows = diagram.FindInitialNetworkRows();
foreach (var findRow in rows)
{
long objectID = findRow.ObjectID;
Guid guid = findRow.GlobalID;
GeometryType geometryType = findRow.GeometryType;
int sourceID = findRow.SourceID;
}
}

更改网络逻辑示意图的布局

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public void DiagramElementQueryResultAndNetworkDiagramSubsetClasses(Geodatabase geodatabase, DiagramManager diagramManager, string diagramName)
{
// Retrieve a diagram
using (NetworkDiagram diagramTest = diagramManager.GetNetworkDiagram(diagramName))
{
// Create a DiagramElementQueryByElementTypes query object to get the diagram elements we want to work with
DiagramElementQueryByElementTypes query = new DiagramElementQueryByElementTypes();
query.QueryDiagramJunctionElement = true;
query.QueryDiagramEdgeElement = true;
query.QueryDiagramContainerElement = true;

// Retrieve those diagram elements
DiagramElementQueryResult elements = diagramTest.QueryDiagramElements(query);

// Create a NetworkDiagramSubset object to edit this set of diagram elements
NetworkDiagramSubset subset = new NetworkDiagramSubset();
subset.DiagramJunctionElements = elements.DiagramJunctionElements;
subset.DiagramEdgeElements = elements.DiagramEdgeElements;
subset.DiagramContainerElements = elements.DiagramContainerElements;

// Edit the shapes of the diagram elements - left as an exercise for the student
TranslateDiagramElements(subset);

// Save the new layout of the diagram elements
diagramTest.SaveLayout(subset, true);
}
}

编辑网络图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public void EditDiagram(NetworkDiagram diagram, List<Guid> globalIDs)
{
// These routines generate their own editing transaction, and therefore cannot be wrapped
// in a separate transaction. Because the editing performed by these routines cannot
// be undone, thise routines can also not be called within an editing session. All
// edits in the current edit session must be saved or discarded before calling these
// routines.

// refresh the diagram - synchronizes it based on the latest network topology
diagram.Update();

// append features to the diagram
diagram.Append(globalIDs);

// overite the diagram with a set of features
diagram.Overwrite(globalIDs);

NetworkDiagramInfo info = diagram.GetDiagramInfo();
if (info.CanExtend)
{
diagram.Extend(NetworkDiagramExtendType.ExtendByContainment);

// or extend for only a set of utility network globalIDs
diagram.Extend(NetworkDiagramExtendType.ExtendByContainment, globalIDs);
}
// delete a diagran
diagram.Delete();
}

}