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

419
2
12-15-2010 09:57 AM
sailiTang
New Contributor III
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
0 Kudos
2 Replies
sailiTang
New Contributor III
Does anyone know it and tell me? Thank you.

Saili
0 Kudos
JeffMatson
Occasional Contributor III
Does anyone know it and tell me? Thank you.

Saili


The topology will still return the endpoints of the lines, even if they are outside of your user defined envelope.  You could try using the SelectByGeometry method to only return the nodes inside the envelope.

Another thing to mention is that if your topology has other feature classes participating in it, any places where the geometry of any participating feature classes intersect, a node will be returned....whether the other feature classes are present in the map document or not.
0 Kudos