Hi all,
I need to to generate an adjacency matrix for a set of facilities on a network. Then output should be a table where you have the facility ID in the first column, its immediate neighboring facilities in the second column, and the distance between them in the third. For example:
1, 2, 24.06
1, 3, 96.33
2, 1, 24.06
3, 1, 148.79
etc.
There is a forum thread on a similar issue from 2008 that resolved the adjacency matrix for the nodes of the network (VB code below). I basically need to do the same thing, except for facilities on the network, not nodes. Is there some ArcObject, similar to 'network forward star', that would get to adjacencies between network facilities? I would ideally like to do this in Python, but VB ok if not feasible. All help appreciated, thanks,
Andres
Public Sub List_Adjacent_Junctions()
On Error GoTo eh
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pNLayer As INetworkLayer
Set pNLayer = pMxDoc.FocusMap.Layer(0)
Dim pND As INetworkDataset
Set pND = pNLayer.NetworkDataset
Dim pNQ As INetworkQuery
Set pNQ = pND
Dim pEnumNE As IEnumNetworkElement
Set pEnumNE = pNQ.Elements(esriNETJunction)
Dim pNEdge As INetworkEdge
Set pNEdge = pNQ.CreateNetworkElement(esriNETEdge)
Dim pNEFromJunc As INetworkJunction
Set pNEFromJunc = pNQ.CreateNetworkElement(esriNETJunction)
Dim pNEToJunc As INetworkJunction
Set pNEToJunc = pNQ.CreateNetworkElement(esriNETJunction)
Dim pNE As INetworkElement
Set pNE = pEnumNE.Next
Dim pNEJunc As INetworkJunction
Set pNEJunc = pNE
'here start the code to store the output on a text file
Dim strOutputFile As String
strOutputFile = "C:\my.txt"
Open strOutputFile For Output As #1
Dim i As Integer
Do Until pNE Is Nothing
For i = 0 To pNEJunc.EdgeCount - 1 'For each connected edge...
pNEJunc.QueryEdge i, True, pNEdge 'Get that connected edge
pNEdge.QueryJunctions pNEFromJunc, pNEToJunc 'Get To junction of current edge
Print #1, pNEFromJunc.EID & ", "; pNEToJunc.EID & ","; pNEdge.AttributeValueByName("Length") 'List the adjacency and the edge's length
Next
Set pNE = pEnumNE.Next
Loop
Exit Sub
Close #1
eh:
MsgBox "Error: " & Err.Description
End Sub