Adjacency matrix for network facitlities

2353
6
03-27-2011 05:18 PM
AndresSevtsuk
New Contributor
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
Tags (2)
0 Kudos
6 Replies
AndresSevtsuk
New Contributor
One more clarification - it is like creating an OD matrix between facilities, but limiting the matrix to only the first ring of neighboring facilities...
Andres
0 Kudos
JaySandhu
Esri Regular Contributor
Why not use OD Cost Matrix? If you load your locations as origins and destinations and then solve for two closest. Ignore the first as that is itself and the second closest will be be closest among all others.

Jay Sandhu
0 Kudos
AndresSevtsuk
New Contributor
Hi Jay,

thanks, but that won't do the trick. That would only get the one closest facility listed, what I need is all closest facilities in every direction on the network. If a facility is in a middle of a street, then there might be two closest facilities, one on either side. If a facility is near an intersections, then there might be 4, one on each branching route and so on.

One very slow way of getting to this could be to
a) solve for the nearest facility, register that facility in a table
b) use that facility as a point barrier, and solve again for the next closest facility, register that in a table
c) keep on going until no more solutions found.

Problem is that I have some 30,000+ facilities, this would take a long time... I'm looking for sth more efficient...

Thanks,

Andres

Why not use OD Cost Matrix? If you load your locations as origins and destinations and then solve for two closest. Ignore the first as that is itself and the second closest will be be closest among all others.

Jay Sandhu
0 Kudos
JaySandhu
Esri Regular Contributor
Andres,

The process you described is probably the best you can do with less programming
for the type of adjacency that you descibe.

Assuming on an average 3 adjacent locations, 30,000 times 3 is 90,000 solves.
And since these routes should be small, individual solves should happen quite quick.
So the whole process may finish in a day.

Jay Sandhu
0 Kudos
AndresSevtsuk
New Contributor
you mention "with less programming"... would there be of a more efficient way involving more programming? using arc objects?
0 Kudos
JaySandhu
Esri Regular Contributor
It will be more efficent if you wrote your own network traversal, simillar to service area but now you are in the realm of graph algorithms and yes, arcobject to access the network forward star. I would not recommend this path as it will take longer to write/debug this approach as opposed to the one day run time of the approach outlined previously.

In any case, the other approaches will still have to solve for each 30,000 origins to determine the adjacenies. There is no additional information that will say which are the adjacent locations without running a search from each origin location.

Jay Sandhu
0 Kudos