sailitang

The code counts the wrong number of nodes for a topology, why?

Discussion created by sailitang on Dec 15, 2010
Latest reply on Dec 17, 2010 by jeffmatson
Hi,

   This is the code for counting the number of nodes and edges for a topology.

Private Sub CursorCount_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
Dim pmXDoc As IMxDocument
Set pmXDoc = ThisDocument

Dim pTopologyLayer As ITopologyLayer
Dim pTopology As ITopology
Dim pTopoGraph As ITopologyGraph
Dim pCursor As ICursor
Dim pEnumTopoNode As IEnumTopologyNode
Dim i As Long
Dim pTopoNode As ITopologyNode
Dim penumNodeEdge As IEnumNodeEdge
Dim pTopoEdge As ITopologyEdge
Dim batfrom As Boolean
Dim pPolyline As IPolyline

Dim pEnv As IEnvelope
Dim pRubber As IRubberBand
Set pRubber = New RubberEnvelope


Dim pActiveView As IActiveView
Set pActiveView = pmXDoc.ActiveView
Set pEnv = pRubber.TrackNew(pActiveView.screenDisplay, Nothing)

Set pTopologyLayer = pmXDoc.FocusMap.Layer(0) 'A topology has to be in first position in the view Table of content
Set pTopology = pTopologyLayer.Topology 'Get the topology
Set pTopoGraph = pTopology.Cache 'Get the topologygraph
pTopoGraph.Build pEnv, False 'Build the topology graph
Set pEnumTopoNode = pTopoGraph.Nodes 'Get all the nodes of the graph
'For each nodes get the adjacent edges and print the length of the edges
MsgBox "Number of nodes : " & pEnumTopoNode.Count
For i = 0 To pEnumTopoNode.Count - 1
   Set pTopoNode = pEnumTopoNode.Next
   Set penumNodeEdge = pTopoNode.Edges(True) 'Get all the adjacent edges
   MsgBox "Number of edges adjacent to that node : " & penumNodeEdge.Count
   MsgBox "Is the enumerator Clockwise : " & penumNodeEdge.IsClockwise
   penumNodeEdge.Next pTopoEdge, batfrom 'Get the next adjacent edge
   While Not pTopoEdge Is Nothing
      Set pPolyline = pTopoEdge.Geometry
      Debug.Print "Length of polyline : " & pPolyline.Length
      penumNodeEdge.Next pTopoEdge, batfrom 'Get the next edge
   Wend
Next

End Sub

But the counting result is wrong. Please see the picture in the attachment. The number of nodes in the area of the picture should be 1, but the result of the code is 4. Could you tell me how to fix it?

Thanks

Saili

Outcomes