I need to populate FNODE and TNODE fields for my roads dataset. I have an intersections point feature class that has unique ids, and I need each road segment to have an FNODE and TNODE value that corresponds to the intersection id. The roads are broken into segments at each intersection so that each segment only touches 2 intersection points. I thought that maybe Network Analyst generated these, but it doesn't look like it actually writes these values. Does anyone know how to generate these?

This dataset won't be used in Network Analyst - it will be used in a custom legacy add in that a client uses.


Just figured out this in VBA. Before running this make a backup (not well error handled). First layer should be the Intersection point layer and second layer should be the road layer. make sure you have started Editing.

The code spatially identifies the point features on the start and end points of every line feature and Updates the OBJECTID values to FNODE and TNODE fields.

Sub UpdateFromTo()
Dim pMxDoc As IMxDocument
Dim pMap As IMap

Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap

Dim pointFtrLyr As IFeatureLayer
Set pointFtrLyr = pMap.Layer(0)

Dim lineFtrLyr As IFeatureLayer
Set lineFtrLyr = pMap.Layer(1)

Dim lineFC As IFeatureClass
Set lineFC = lineFtrLyr.FeatureClass
Dim fromNodeIndex As Integer
fromNodeIndex = lineFC.FindField("FNODE")
Dim toNodeIndex As Integer
toNodeIndex = lineFC.FindField("TNODE")

Dim pFI2 As IFeatureIndex2
Set pFI2 = New FeatureIndex

Set pFI2.FeatureClass = pointFtrLyr.FeatureClass
Set pFI2.OutputSpatialReference("Shape") = pMxDoc.FocusMap.SpatialReference
pFI2.Index Nothing, pointFtrLyr.AreaOfInterest

Dim m_IQ2 As IIndexQuery2
Set m_IQ2 = pFI2

Dim pID As New UID
pID = "esriEditor.Editor"
Dim pEditor As IEditor
Set pEditor = Application.FindExtensionByCLSID(pID)


Dim pLineCursor As IFeatureCursor
Set pLineCursor = lineFtrLyr.Search(Nothing, False)

Dim pLineFeature As IFeature
Set pLineFeature = pLineCursor.NextFeature

Dim foid As Long
Dim toid As Long
Dim fdist As Double
Dim tdist As Double

Do While Not pLineFeature Is Nothing

Dim pLine As IPolyline
Set pLine = pLineFeature.Shape
m_IQ2.NearestFeature pLine.FromPoint, foid, fdist

If Round(fdist, 0) = 0 Then

    pLineFeature.Value(pLineFeature.Fields.FindField("FNODE")) = foid

End If

m_IQ2.NearestFeature pLine.ToPoint, toid, tdist

If Round(tdist, 0) = 0 Then

    pLineFeature.Value(pLineFeature.Fields.FindField("TNODE")) = toid

End If

Set pLineFeature = pLineCursor.NextFeature

pEditor.StopOperation "Calculate FromTo Nodes"

MsgBox "Features updated!!"

End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.