I'm somewhat new using the Network Analyst extension and running into a problem I can't figure out how to solve.
I built a network dataset from a street centerlines layer. What I want to do is, using the junctions layer (nodes at the intersections of the streets), create a table that gives the distance between the origin node and the closest other nodes in each direction.
The O-D Cost Matrix tool seemed like the way to go, but the problem is it gives me distances between the origin node and all subsequent nodes along the path within the specified search tolerance.
What I want is only the first node along each path from the origin node. I attached a picture to try and explain this better.
Any suggestions or help would be EXTREMELY appreciated.
Josh, What you need for each junction is simply the adjacent junctions and cost to them. You do not need to use any solver (shortest path, OD, etc) to do this. You can simply add the network dataset to ArcMap and then use the VBA below. This VBA lists out the adjacent junctions to each junction in the network and the cost (based on an attribute called "minutes") to get to that junction. You can customize it as needed. For example, change the EID to OID and/or change the cost attribute you need to list out. Currently it is set to show the results in the immediate window of VBA but you can customize it to write to a file. Regards. Jay Sandhu
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) 'Assume the Network dataset is first layer in TOC 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 Dim i As Integer Do Until pNE Is Nothing Debug.Print "Junction: " & pNEJunc.EID & " is adjacent to: " & pNEJunc.EdgeCount & " junctions." 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 Debug.Print " Adjacent Junction: " & pNEToJunc.EID & " Cost = " & pNEdge.AttributeValueByName("minutes") 'List the adjacency and cost to it Next Set pNE = pEnumNE.Next Loop Exit Sub eh: MsgBox "Error: " & Err.Description End Sub
The only odd thing is I'm getting some records of adjacent nodes that, when viewed on the map, don't appear to be connected at all with the origin nodes. This may be an issue with the network dataset though because everything looks fine with the code. Perhaps dissolving the network will help.
In any case, the VBA code seems to work and I modified it to output to a text file.
As far as the non-adjacent junction problems, I doubt that dissolve will fix any connectivity issues. You may look at the junctions that are not adjacent and also look at using the Network Identify tool (second tool from right on the NA toolbar) to click on these junctions and see what is adjacent.
Hmmm...this is probably something silly I'm just overlooking. Maybe something to do with the Object ID's of the Junctions layer?
Attached is a ZIP of the output file using the VBA code you sent. Also at (http://www.wxalert.info/work/streets.zip) is a ZIP file of my Junctions layer and the Street Centerlines layer I'm using for the Network Dataset. The file size was a bit too large to upload here (~ 3.5 MB).
As an example...if you open the CSV file (output) you can see that Node #3 is adjacent to Node #1310, but if you select ObjectIDs #3 and #1310 from the Junctions layer, they're not even close.
Again, I'm probably just missing something silly here, but any guidance would be appreciated.
I am pretty sure the issue is the VBA code gets EIDs and what I need are the OIDs from the junctions layer.
I just changed .EID to .OID in the code and it seems to have worked. Is that correct?
Edit: This seems to be working, so unless I'm missing something, changed EID to OID in the code seemed to work. But if anyone thinks I'm missing something, please let me know. Thanks again for the help Jay!