TheoBallis

Pass Weights to CreateForwardStar Method - VBA

Discussion created by TheoBallis on May 14, 2012
Hello!

First of all I would like to mention that a I am an amateur ArcObjects user, that's why my code does not seem professional.

I'm trying to perform a network Analysis to a given network without the Network Analyst (I am not an owner of a license).
After having created inside my personal geodatabase the geometric network (through the ArcCatalog Wizard) of a given polyline network and assigned weights to the links,
I am trying to "traverse" it by using the ForwardStar method.

Here's the code.

Private Sub GetNodes()

Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

Dim pAWFactory As IWorkspaceFactory
Set pAWFactory = New AccessWorkspaceFactory

Dim pFeatWorkspace As IFeatureWorkspace
Set pFeatWorkspace = pAWFactory.OpenFromFile("FilePath", 0) 'I Give the FilePath manually

Dim pFeatDataSet As IFeatureDataset
Set pFeatDataSet = pFeatWorkspace.OpenFeatureDataset("FeatDataset")

Dim pNetCollection As INetworkCollection
Set pNetCollection = pFeatDataSet

Dim pGeomNet As IGeometricNetwork
Set pGeomNet = pNetCollection.GeometricNetworkByName("FeatDataset_Net")

Dim pNet As INetwork
Set pNet = pGeomNet.Network

Dim pEdgeWeight As INetWeight
Set pEdgeWeight = pNetSchema.WeightByName("LENGTH") 'The field from where the weights should be extracted 

Dim pForStar As IForwardStar
Set pForStar = pGeomNet.Network.CreateForwardStar(False, pEdgeWeight, pEdgeWeight, pEdgeWeight, Nothing)
                                               
Dim lCnt As Long
Dim AdjW As Double
Dim AdjEdgeEID As Long
Dim li As Long

li = 2 'Just a number for test

pForStar.FindAdjacent 0, li, lCnt
pForStar.QueryAdjacentEdge 0, AdjEdgeEID, False, AdjW


MsgBox "Edge = " & AdjEdgeEID & " " & "Weight = " & AdjW

End Sub

Although the AdjEdgeEID returns a logical number the AdjW keeps returning 0

Could anyone provide me with some help? 

Thank you in advance!

Outcomes