Select to view content in your preferred language

calculate the fnode tnode of a polyline shapefile

4123
3
04-17-2013 04:37 AM
NaserHdieb
New Contributor
how to calculate the fnode tnode of a polyline shapefile ? I tried network analyst but i could not create From Node to Node attribute in the line shapefile.... I have a node point shapefile and a line shapefile (center roads of alexandria VA) that I created from Network anaylyst. ...any help is appreciated
Tags (2)
0 Kudos
3 Replies
JaySandhu
Esri Regular Contributor
The network topology, that is, the from/to junctions for each edge is stored in the binary files of the network dataset. In general you do no need this information. May I ask what you intend to do with that information?
The way to get this information is to use ArcObjects to retrieve the values from the network dataset.
I am including a small VBA that you can run (if you have VBA installed) and it will write out the edge OID and the two from/to junction OIDs to a text file. Make sure the network dataset is added to ArcMap as the first layer when you run this VBA.
Jay Sandhu

Public Sub List_ND_Topology_ToDisk()
  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(esriNETEdge)
  
  Dim pFromJunction As INetworkJunction
  Set pFromJunction = pNQ.CreateNetworkElement(esriNETJunction)
  
  Dim pToJunction As INetworkJunction
  Set pToJunction = pNQ.CreateNetworkElement(esriNETJunction)
  
  Dim pNE As INetworkElement
  Set pNE = pEnumNE.Next
  
  Dim pNEdge As INetworkEdge
  Set pNEdge = pNE
  Dim i As Integer
 Open "c:\temp\ND_FromTo.csv" For Output As #1 'set path as needed
 Print #1, """EdgeOID"", ""FromOID"", ""ToOID"", ""Lenght_Attribute"""
  Do Until pNE Is Nothing
    pNEdge.QueryJunctions pFromJunction, pToJunction
    Print #1, pNE.OID; ","; pFromJunction.OID; ","; pToJunction.OID; ","; pNE.AttributeValue(1)
    Set pNE = pEnumNE.Next
  Loop
   Close #1
   
End Sub
0 Kudos
NaserHdieb
New Contributor
Thanks! the code works fine. My number of arcs in the dataset is like 5178, and the fromNode and toNode generated file has more arcs. I joined the two attribute table and selected only matched IDs to ignore the extra added arcs. Any comment?



The network topology, that is, the from/to junctions for each edge is stored in the binary files of the network dataset. In general you do no need this information. May I ask what you intend to do with that information?
The way to get this information is to use ArcObjects to retrieve the values from the network dataset.
I am including a small VBA that you can run (if you have VBA installed) and it will write out the edge OID and the two from/to junction OIDs to a text file. Make sure the network dataset is added to ArcMap as the first layer when you run this VBA.
Jay Sandhu

Public Sub List_ND_Topology_ToDisk()
  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(esriNETEdge)
  
  Dim pFromJunction As INetworkJunction
  Set pFromJunction = pNQ.CreateNetworkElement(esriNETJunction)
  
  Dim pToJunction As INetworkJunction
  Set pToJunction = pNQ.CreateNetworkElement(esriNETJunction)
  
  Dim pNE As INetworkElement
  Set pNE = pEnumNE.Next
  
  Dim pNEdge As INetworkEdge
  Set pNEdge = pNE
  Dim i As Integer
 Open "c:\temp\ND_FromTo.csv" For Output As #1 'set path as needed
 Print #1, """EdgeOID"", ""FromOID"", ""ToOID"", ""Lenght_Attribute"""
  Do Until pNE Is Nothing
    pNEdge.QueryJunctions pFromJunction, pToJunction
    Print #1, pNE.OID; ","; pFromJunction.OID; ","; pToJunction.OID; ","; pNE.AttributeValue(1)
    Set pNE = pEnumNE.Next
  Loop
   Close #1
   
End Sub
0 Kudos
JaySandhu
Esri Regular Contributor
Glad to know the VBA worked for you. It lists the edges that are stored in the network. It should be same as the number of arcs in your shape file. is your network dataset  up to date? That is, have you edited your shape file and not re-built the network?

Jay Sandhu
0 Kudos