ArcGIS Developer Help  (EditorExt)    

INetworkAnalysisExtBarriers Example

[Visual Basic 6.0]
 'This example demonstrates how to use the properties and methods on the INetworkAnalysisExtBarriers interface
 'g_pApplication is a variable of type IApplication holding a valid reference to the ArcMap application
 'g_pMxDocument is a variable to type IMxDocument holding a valid reference to the current ArcMap document
 'SDE_CONNECTION_FILE is a string constant containing the path to an SDE connection file
 'FEATUREDATASET1_NAME ia a string constants containing a feature dataset name
 'GEOMETRICNETWORK1_NAME is a string constants containing a geometric network name
 
   Dim pNetworkAnalysisExtBarriers As esriEditorExt.INetworkAnalysisExtBarriers
   Dim pUID As New esriSystem.UID
   Dim pNetworkAnalysisExt As esriEditorExt.INetworkAnalysisExt
   Dim pWorkspaceFactory As esriGeoDatabase.IWorkspaceFactory
   Dim pFeatureWorkspace As esriGeoDatabase.IFeatureWorkspace
   Dim pNetworkCollection As esriGeoDatabase.INetworkCollection
   Dim pGeometricNetwork As esriGeoDatabase.IGeometricNetwork
   Dim pJunctionFlagDisplay As esriNetworkAnalysis.IJunctionFlagDisplay
   Dim pEdgeFlagDisplay As esriNetworkAnalysis.IEdgeFlagDisplay
   Dim pJunctionBarriers As esriNetworkAnalysis.INetElementBarriers
   Dim pEdgeBarriers As esriNetworkAnalysis.INetElementBarriers
   Dim pSelectionSetBarriers As esriNetworkAnalysis.ISelectionSetBarriers
   Dim pFeatureClasses As esriGeoDatabase.IEnumFeatureClass
   Dim pFeatureClass As esriGeoDatabase.IFeatureClass
   Dim pFeature As esriGeoDatabase.IFeature
   Dim pMxDocument As esriArcMapUI.IMxDocument
   Dim pMap As esriCarto.IMap
   Dim pActiveView As esriCarto.IActiveView
   Dim pActiveViewEvents As esriCarto.IActiveViewEvents
   Dim pFeatureLayer As esriCarto.IFeatureLayer
   Dim eAnalysisType As esriEditorExt.esriAnalysisType
   Dim blnDisabledLayer As Boolean
   Dim lngBarrierCount As Long
   Dim lngNetworkCount As Long
   Dim lngFeatureID As Long
   Dim i As Long
   
   'obtain a reference to the interface by querying the application for the Utility Network Analysis extension
   pUID = "esriEditorExt.UtilityNetworkAnalysisExt"
   Set pNetworkAnalysisExtBarriers = g_pApplication.FindExtensionByCLSID(pUID)
 
   'add a geometric network to the extension
   'create a new SDE workspace factory
   Set pWorkspaceFactory = New SdeWorkspaceFactory
   'create a feature workspace using the specified SDE connection file
   Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(SDE_CONNECTION_FILE, 0)
   'get a reference to the INetworkCollection interface of the feature dataset
   Set pNetworkCollection = pFeatureWorkspace.OpenFeatureDataset(FEATUREDATASET1_NAME)
   'get a reference to the geometric network by specifying its name
   Set pGeometricNetwork = pNetworkCollection.GeometricNetworkByName(GEOMETRICNETWORK1_NAME)
   'add the network to the extension
   Set pNetworkAnalysisExt = pNetworkAnalysisExtBarriers
   pNetworkAnalysisExt.AddNetwork pGeometricNetwork
 
   With pNetworkAnalysisExtBarriers
     
     'add junction barriers to the network using the AddJunctionBarrier method
     For i = 0 To 9
       Set pJunctionFlagDisplay = New esriNetworkAnalysis.JunctionFlagDisplay
       .AddJunctionBarrier pJunctionFlagDisplay
     Next i
 
     'get the number of junction barriers on the current network using the JunctionBarrierCount property
     lngBarrierCount = .JunctionBarrierCount
     
     'get a reference to the first junction barrier on the network using the JunctionBarrier property
     Set pJunctionFlagDisplay = .JunctionBarrier(0)
     
     'add edge barriers to the network using the AddEdgeBarrier method
     For i = 0 To 9
       Set pEdgeFlagDisplay = New esriNetworkAnalysis.EdgeFlagDisplay
       .AddEdgeBarrier pEdgeFlagDisplay
     Next i
 
     'get the number of edge barriers on the current network using the EdgeBarrierCount property
     lngBarrierCount = .EdgeBarrierCount
     
     'get a reference to the first edge barrier on the network using the EdgeBarrier property
     Set pEdgeFlagDisplay = .EdgeBarrier(0)
     
     'create NetElementBarrier objects using the CreateElementBarriers method
     .CreateElementBarriers pJunctionBarriers, pEdgeBarriers
     
     'clear the barriers on the current network using the ClearBarriers method
     .ClearBarriers
     
     'determine whether selected or unselected or all features are traced using the SelectionSemantics property
     eAnalysisType = .SelectionSemantics
     
     'specify that only unselected features are to be traced using the SelectionSemantics property
     eAnalysisType = esriAnalysisOnNonSelectedFeatures
     .SelectionSemantics = eAnalysisType
     
     'create a SelectionSetBarrier object using the CreateSelectionBarriers method
     'first, select at least one feature
     Set pFeatureClasses = pGeometricNetwork.ClassesByType(esriFTSimpleJunction)
     pFeatureClasses.Reset
     Set pFeatureClass = pFeatureClasses.Next
     lngFeatureID = 0
     'get a feature from the feature class
     Do
       Set pFeature = pFeatureClass.GetFeature(lngFeatureID)
       If pFeature Is Nothing Then
         lngFeatureID = lngFeatureID + 1
       Else
         Exit Do
       End If
     Loop
     'get a reference to the current map
     Set pMap = g_pMxDocument.FocusMap
     'add the layer to the map
     'first, create a feature layer, and set its feature class
     Set pFeatureLayer = New esriCarto.FeatureLayer
     Set pFeatureLayer.FeatureClass = pFeatureClass
     pFeatureLayer.Name = pFeatureClass.AliasName
     'add this feature layer to the map
     pMap.AddLayer pFeatureLayer
     'now, select the feature on the map
     pMap.SelectFeature pFeatureLayer, pFeature
     'refresh the view
     Set pActiveView = pMap
     pActiveView.PartialRefresh esriViewGraphicSelection, Nothing, Nothing
     'get a SelectionSetBarriers object from the extension
     .CreateSelectionBarriers pSelectionSetBarriers
     
     'determine whether a feature layer is disabled using the GetDisabledLayer method
     blnDisabledLayer = .GetDisabledLayer(pFeatureLayer)
     
     'disable the layer using the SetDisabledLayer method
     blnDisabledLayer = True
     .SetDisabledLayer pFeatureLayer, blnDisabledLayer
     
   End With
 
   'remove all of the networks from the extension using the DeleteNetwork method
   lngNetworkCount = pNetworkAnalysisExt.NetworkCount
   For i = 0 To lngNetworkCount - 1
     Set pGeometricNetwork = pNetworkAnalysisExt.CurrentNetwork
     pNetworkAnalysisExt.DeleteNetwork pGeometricNetwork
   Next i
 
   'remove the layer from the map
   pMap.DeleteLayer pFeatureLayer 
 

[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button Language Filter in the upper-left corner of the page.