Monday, May 4, 2009
disconnected tracing
Public Sub FindConnectedSample()
Dim pEditor As IEditor
Dim pNetworkAnalysisExt As esriCore.INetworkAnalysisExt
Dim pNetworkAnalysisExtResults As esriCore.INetworkAnalysisExtResults
Dim pNetworkAnalysisExtFlags As esriCore.INetworkAnalysisExtFlags
Dim pNetworkAnalysisExtBarriers As esriCore.INetworkAnalysisExtBarriers
Dim pUID As New esriCore.UID
Dim EnumJuncResults As IEnumNetEID
Dim EnumEdgeResults As IEnumNetEID
pUID = "esricore.UtilityNetworkAnalysisExt"
Set pNetworkAnalysisExt = Application.FindExtensionByCLSID(pUID)
Set pEditor = Application.FindExtensionByName("esricore.Editor")
Set pNetworkAnalysisExtResults = pNetworkAnalysisExt
Set pNetworkAnalysisExtFlags = pNetworkAnalysisExt
Set pNetworkAnalysisExtBarriers = pNetworkAnalysisExt
'Remove layers from trace task consideration
Dim pFLayer As IFeatureLayer
Dim lCount As Long
Dim k As Long
lCount = pNetworkAnalysisExt.FeatureLayerCount
For k = 0 To lCount - 2
Set pFLayer = pNetworkAnalysisExt.FeatureLayer(k)
Debug.Print pFLayer.Name
If pFLayer.Name = "Secondaries_util" Or pFLayer.Name = "Service_points_util" Then
pNetworkAnalysisExtBarriers.SetDisabledLayer pFLayer, True
End If
Next k
'Taking care of the trace task...
Dim pTraceTasks As esriCore.ITraceTasks
Set pTraceTasks = pNetworkAnalysisExt 'QI
Dim pTraceTask As esriCore.ITraceTask
Dim pTraceTaskResults As ITraceTaskResults
Dim lResults As Long
'Ok, we're going to enummerate through each task based on the count
'to make sure we are setting the right one
Dim i, j As Long
i = pTraceTasks.TaskCount - 1
For j = 0 To i
Set pTraceTask = pTraceTasks.Task(j)
If pTraceTask.Name = "Find Connected" Then Exit For
Next
'Set the Current task to Find Connected
Set pTraceTasks.CurrentTask = pTraceTask
'QI to the TraceTaskResults to get the Enum of Junctions and Edges
Set pTraceTaskResults = pTraceTask 'QI
'If the Solve is not enabled, exit...
If Not pTraceTask.EnableSolve Then
Exit Sub
End If
'Execute the trace
pTraceTask.OnTraceExecution
'Get the results of the trace
lResults = pNetworkAnalysisExtResults.ResultFeatureCount
Set EnumJuncResults = pTraceTaskResults.ResultJunctions
Set EnumEdgeResults = pTraceTaskResults.ResultEdges
End Sub
Dim pEditor As IEditor
Dim pNetworkAnalysisExt As esriCore.INetworkAnalysisExt
Dim pNetworkAnalysisExtResults As esriCore.INetworkAnalysisExtResults
Dim pNetworkAnalysisExtFlags As esriCore.INetworkAnalysisExtFlags
Dim pNetworkAnalysisExtBarriers As esriCore.INetworkAnalysisExtBarriers
Dim pUID As New esriCore.UID
Dim EnumJuncResults As IEnumNetEID
Dim EnumEdgeResults As IEnumNetEID
pUID = "esricore.UtilityNetworkAnalysisExt"
Set pNetworkAnalysisExt = Application.FindExtensionByCLSID(pUID)
Set pEditor = Application.FindExtensionByName("esricore.Editor")
Set pNetworkAnalysisExtResults = pNetworkAnalysisExt
Set pNetworkAnalysisExtFlags = pNetworkAnalysisExt
Set pNetworkAnalysisExtBarriers = pNetworkAnalysisExt
'Remove layers from trace task consideration
Dim pFLayer As IFeatureLayer
Dim lCount As Long
Dim k As Long
lCount = pNetworkAnalysisExt.FeatureLayerCount
For k = 0 To lCount - 2
Set pFLayer = pNetworkAnalysisExt.FeatureLayer(k)
Debug.Print pFLayer.Name
If pFLayer.Name = "Secondaries_util" Or pFLayer.Name = "Service_points_util" Then
pNetworkAnalysisExtBarriers.SetDisabledLayer pFLayer, True
End If
Next k
'Taking care of the trace task...
Dim pTraceTasks As esriCore.ITraceTasks
Set pTraceTasks = pNetworkAnalysisExt 'QI
Dim pTraceTask As esriCore.ITraceTask
Dim pTraceTaskResults As ITraceTaskResults
Dim lResults As Long
'Ok, we're going to enummerate through each task based on the count
'to make sure we are setting the right one
Dim i, j As Long
i = pTraceTasks.TaskCount - 1
For j = 0 To i
Set pTraceTask = pTraceTasks.Task(j)
If pTraceTask.Name = "Find Connected" Then Exit For
Next
'Set the Current task to Find Connected
Set pTraceTasks.CurrentTask = pTraceTask
'QI to the TraceTaskResults to get the Enum of Junctions and Edges
Set pTraceTaskResults = pTraceTask 'QI
'If the Solve is not enabled, exit...
If Not pTraceTask.EnableSolve Then
Exit Sub
End If
'Execute the trace
pTraceTask.OnTraceExecution
'Get the results of the trace
lResults = pNetworkAnalysisExtResults.ResultFeatureCount
Set EnumJuncResults = pTraceTaskResults.ResultJunctions
Set EnumEdgeResults = pTraceTaskResults.ResultEdges
End Sub
Subscribe to:
Posts (Atom)