ArcGIS Developer Help  (EditorExt)    

INetworkAnalysisExt Example

[Visual Basic 6.0]
 'This example demonstrates how to use the properties and methods on the INetworkAnalysisExt interface.
 'g_pApplication is a variable of type IApplication holding a valid reference to the ArcMap application
 '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
 'FEATUREDATASET2_NAME ia a string constants containing a feature dataset name
 'GEOMETRICNETWORK2_NAME is a string constants containing a geometric network name
 
   Dim pNetworkAnalysisExt As esriEditorExt.INetworkAnalysisExt
   Dim pUID As New esriSystem.UID
   Dim pApplication As esriFramework.IApplication
   Dim pWorkspaceFactory As esriGeoDatabase.IWorkspaceFactory
   Dim pFeatureWorkspace As esriGeoDatabase.IFeatureWorkspace
   Dim pNetworkCollection As esriGeoDatabase.INetworkCollection
   Dim pGeometricNetwork As esriGeoDatabase.IGeometricNetwork
   Dim pFeatureClasses As esriGeoDatabase.IEnumFeatureClass
   Dim pFeatureClass As esriGeoDatabase.IFeatureClass
   Dim pFeatureLayer As esriCarto.IFeatureLayer
   Dim lngNetworkCount As Long
   Dim lngFeatureLayerCount As Long
   Dim lngSnapTolerance 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 pNetworkAnalysisExt = g_pApplication.FindExtensionByCLSID(pUID)
 
   With pNetworkAnalysisExt
 
     'get a reference to the parent application using the Application property
     Set pApplication = .Application
     
     'get the snapping tolerance using the SnapTolerance property
     lngSnapTolerance = .SnapTolerance
     
     'set the snapping tolerance to 20 pixels
     lngSnapTolerance = 20
     .SnapTolerance = lngSnapTolerance
     
     'add a geometric network to the extension using the AddNetwork method
     '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
     .AddNetwork pGeometricNetwork
   
     'add a geometric network to the extension by adding a layer from the network
     'get a reference to a new feature dataset
     Set pNetworkCollection = pFeatureWorkspace.OpenFeatureDataset(FEATUREDATASET2_NAME)
     'get a reference to a new geometric network
     Set pGeometricNetwork = pNetworkCollection.GeometricNetworkByName(GEOMETRICNETWORK2_NAME)
     'there must be at least one simple junction feature class in the network
     'get a reference to all of the simple junction feature classes in the network
     Set pFeatureClasses = pGeometricNetwork.ClassesByType(esriFTSimpleJunction)
     pFeatureClasses.Reset
     'obtain a reference to the first feature class in the collection
     Set pFeatureClass = pFeatureClasses.Next
     'create a new feature layer, and assign the feature class to this layer
     Set pFeatureLayer = New esriCarto.FeatureLayer
     Set pFeatureLayer.FeatureClass = pFeatureClass
     'add the layer to the extension
     .AddLayer pFeatureLayer
     
     'determine how many networks are loaded using the NetworkCount property
     lngNetworkCount = .NetworkCount
     
     'get a reference to a geometric network using the Network property
     Set pGeometricNetwork = .Network(0)
     
     'get a reference to the current network using the CurrentNetwork property
     Set pGeometricNetwork = .CurrentNetwork
     
     'set the current network to be the first network loaded using the CurrentNetwork property
     Set pGeometricNetwork = .Network(0)
     Set .CurrentNetwork = pGeometricNetwork
     
     'determine the number of layers from the current network are loaded on the extension using the FeatureLayerCount property
     Set pGeometricNetwork = .Network(1)
     Set .CurrentNetwork = pGeometricNetwork
     lngFeatureLayerCount = .FeatureLayerCount
     
     'get a reference to a feature layer loaded on the extension using the FeatureLayer property
     Set pFeatureLayer = .FeatureLayer(0)
     
     'remove a network from the extension by removing a layer using the DropLayer method
     .DropLayer pFeatureLayer
     
     'remove all of the networks from the extension using the DeleteNetwork method
     lngNetworkCount = .NetworkCount
     For i = 0 To lngNetworkCount - 1
       Set pGeometricNetwork = .CurrentNetwork
       .DeleteNetwork pGeometricNetwork
     Next i
     
   End With 
 

[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.