![]() |
This document is archived and information here might be outdated. Recommended version. |
Loop through a network dataset and display adjacencies for each junction in a message box.
///<summary>Loop through a network dataset and display adjacencies for each junction in a message box.</summary>
///
///<param name="networkDataset">An INetworkDataset interface.</param>
///
///<remarks></remarks>
public void DisplayNetworkAdjacencyInMessageBox(ESRI.ArcGIS.Geodatabase.INetworkDataset networkDataset)
{
if (networkDataset == null)
{
return;
}
ESRI.ArcGIS.Geodatabase.INetworkQuery networkQuery=((ESRI.ArcGIS.Geodatabase.INetworkQuery)(networkDataset));
ESRI.ArcGIS.Geodatabase.INetworkElement edgeNetworkElement=networkQuery.CreateNetworkElement(ESRI.ArcGIS.Geodatabase.esriNetworkElementType.esriNETEdge);
ESRI.ArcGIS.Geodatabase.INetworkEdge networkEdge=((ESRI.ArcGIS.Geodatabase.INetworkEdge)(edgeNetworkElement)); // Explicit Cast
// Get the from network junction
ESRI.ArcGIS.Geodatabase.INetworkElement fromJunctionNetworkElement=networkQuery.CreateNetworkElement(ESRI.ArcGIS.Geodatabase.esriNetworkElementType.esriNETJunction);
ESRI.ArcGIS.Geodatabase.INetworkJunction fromNetworkJunction=((ESRI.ArcGIS.Geodatabase.INetworkJunction)(fromJunctionNetworkElement)); // Explicit Cast
// Get the to network junction
ESRI.ArcGIS.Geodatabase.INetworkElement toJunctionNetworkElement=networkQuery.CreateNetworkElement(ESRI.ArcGIS.Geodatabase.esriNetworkElementType.esriNETJunction);
ESRI.ArcGIS.Geodatabase.INetworkJunction toNetworkJunction=((ESRI.ArcGIS.Geodatabase.INetworkJunction)(toJunctionNetworkElement)); // Explicit Cast
ESRI.ArcGIS.Geodatabase.IEnumNetworkElement enumNetworkElement=networkQuery.get_Elements(ESRI.ArcGIS.Geodatabase.esriNetworkElementType.esriNETJunction); // Explicit Cast
ESRI.ArcGIS.Geodatabase.INetworkElement networkElement=enumNetworkElement.Next();
ESRI.ArcGIS.Geodatabase.INetworkJunction networkJunction=((ESRI.ArcGIS.Geodatabase.INetworkJunction)(networkElement)); // Explicit Cast
while (!(networkElement == null))
{
System.String messageString="Junction: " + networkJunction.EID + " is adjacent to: " + networkJunction.EdgeCount + " junctions." + System.Environment.NewLine;
for (System.Int32 i=0; i <= networkJunction.EdgeCount - 1; i++)
{
networkJunction.QueryEdge(i, true, networkEdge);
networkEdge.QueryJunctions(fromNetworkJunction, toNetworkJunction);
messageString=messageString + "Adjacent Junction: " + toNetworkJunction.EID + System.Environment.NewLine;
}
System.Windows.Forms.MessageBox.Show(messageString, "Network Adjacency", System.Windows.Forms.MessageBoxButtons.OK);
networkElement=enumNetworkElement.Next();
}
}
'''<summary>Loop through a network dataset and display adjacencies for each junction in a message box.</summary>
'''
'''<param name="networkDataset">An INetworkDataset interface.</param>
'''
'''<remarks></remarks>
Public Sub DisplayNetworkAdjacencyInMessageBox(ByVal networkDataset As ESRI.ArcGIS.Geodatabase.INetworkDataset)
If networkDataset Is Nothing Then
Return
End If
Dim networkQuery As ESRI.ArcGIS.Geodatabase.INetworkQuery=(CType(networkDataset, ESRI.ArcGIS.Geodatabase.INetworkQuery)) ' Explict Cast
Dim edgeNetworkElement As ESRI.ArcGIS.Geodatabase.INetworkElement=networkQuery.CreateNetworkElement(ESRI.ArcGIS.Geodatabase.esriNetworkElementType.esriNETEdge)
Dim networkEdge As ESRI.ArcGIS.Geodatabase.INetworkEdge=(CType(edgeNetworkElement, ESRI.ArcGIS.Geodatabase.INetworkEdge)) ' Explicit Cast
' Get the from network junction
Dim fromJunctionNetworkElement As ESRI.ArcGIS.Geodatabase.INetworkElement=networkQuery.CreateNetworkElement(ESRI.ArcGIS.Geodatabase.esriNetworkElementType.esriNETJunction)
Dim fromNetworkJunction As ESRI.ArcGIS.Geodatabase.INetworkJunction=(CType(fromJunctionNetworkElement, ESRI.ArcGIS.Geodatabase.INetworkJunction)) ' Explicit Cast
' Get the to network junction
Dim toJunctionNetworkElement As ESRI.ArcGIS.Geodatabase.INetworkElement=networkQuery.CreateNetworkElement(ESRI.ArcGIS.Geodatabase.esriNetworkElementType.esriNETJunction)
Dim toNetworkJunction As ESRI.ArcGIS.Geodatabase.INetworkJunction=(CType(toJunctionNetworkElement, ESRI.ArcGIS.Geodatabase.INetworkJunction)) ' Explicit Cast
Dim enumNetworkElement As ESRI.ArcGIS.Geodatabase.IEnumNetworkElement=networkQuery.Elements(ESRI.ArcGIS.Geodatabase.esriNetworkElementType.esriNETJunction) ' Explicit Cast
Dim networkElement As ESRI.ArcGIS.Geodatabase.INetworkElement=enumNetworkElement.Next()
Dim networkJunction As ESRI.ArcGIS.Geodatabase.INetworkJunction=(CType(networkElement, ESRI.ArcGIS.Geodatabase.INetworkJunction)) ' Explicit Cast
Dim i As System.Int32
Do Until networkElement Is Nothing
Dim messageString As String
messageString="Junction: " + networkJunction.EID.ToString + " is adjacent to: " + networkJunction.EdgeCount.ToString + " junctions." + System.Environment.NewLine
For i=0 To networkJunction.EdgeCount - 1 'For each connected edge...
networkJunction.QueryEdge(i, True, networkEdge) 'Get that connected edge
networkEdge.QueryJunctions(fromNetworkJunction, toNetworkJunction) 'Get To junction of current edge
messageString=messageString + "Adjacent Junction: " + toNetworkJunction.EID.ToString + System.Environment.NewLine 'List the adjacency
Next i
System.Windows.Forms.MessageBox.Show(messageString, "Network Adjacency", System.Windows.Forms.MessageBoxButtons.OK)
networkElement=enumNetworkElement.Next
Loop
End Sub