[Visual Basic 6.0]'This example demonstrates how to use the properties and methods on the INetworkAnalysisExtResults 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 constant containing a feature dataset name 'GEOMETRICNETWORK1_NAME is a string constant containing a geometric network name Dim pNetworkAnalysisExtResults As esriEditorExt.INetworkAnalysisExtResults 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 pNetElements As esriGeoDatabase.INetElements Dim pJunctionResults As esriGeoDatabase.IEnumNetEID Dim pEdgeResults As esriGeoDatabase.IEnumNetEID Dim pJunctionFlag As esriNetworkAnalysis.INetFlag Dim pTraceFlowSolver As esriNetworkAnalysis.ITraceFlowSolver Dim pNetSolver As esriNetworkAnalysis.INetSolver Dim pFeatureClasses As esriGeoDatabase.IEnumFeatureClass Dim pFeatureClass As esriGeoDatabase.IFeatureClass Dim pFeatureLayer As esriCarto.IFeatureLayer Dim pMap As esriCarto.IMap Dim lngJunctionEID As Long Dim lngUserClassID As Long Dim lngUserID As Long Dim lngUserSubID As Long Dim lngNumElementsInDrawing As Long Dim lngNumFeaturesSelected As Long Dim lngNetworkCount As Long Dim lngLayerCount As Long Dim blnDrawComplex As Boolean Dim blnResultsAsSelection As Boolean Dim i As Long 'obtain a reference to the interface by querying the application for the Utility Network Analysis extension pUID = "esriEditorExt.UtilityNetworkAnalysisExt" Set pNetworkAnalysisExtResults = 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 = pNetworkAnalysisExtResults pNetworkAnalysisExt.AddNetwork pGeometricNetwork 'add the layer for each feature class in the geometic network Set pMap = g_pMxDocument.FocusMap 'get the simple edge feature classes Set pFeatureClasses = pGeometricNetwork.ClassesByType(esriFTSimpleEdge) pFeatureClasses.Reset Do Set pFeatureClass = pFeatureClasses.Next If pFeatureClass Is Nothing Then Exit Do Set pFeatureLayer = New esriCarto.FeatureLayer pFeatureLayer.Name = pFeatureClass.AliasName Set pFeatureLayer.FeatureClass = pFeatureClass pMap.AddLayer pFeatureLayer Loop 'get the complex edge feature classes Set pFeatureClasses = pGeometricNetwork.ClassesByType(esriFTComplexEdge) pFeatureClasses.Reset Do Set pFeatureClass = pFeatureClasses.Next If pFeatureClass Is Nothing Then Exit Do Set pFeatureLayer = New esriCarto.FeatureLayer pFeatureLayer.Name = pFeatureClass.AliasName Set pFeatureLayer.FeatureClass = pFeatureClass pMap.AddLayer pFeatureLayer Loop 'get the simple junction feature classes Set pFeatureClasses = pGeometricNetwork.ClassesByType(esriFTSimpleJunction) pFeatureClasses.Reset Do Set pFeatureClass = pFeatureClasses.Next If pFeatureClass Is Nothing Then Exit Do Set pFeatureLayer = New esriCarto.FeatureLayer pFeatureLayer.Name = pFeatureClass.AliasName Set pFeatureLayer.FeatureClass = pFeatureClass pMap.AddLayer pFeatureLayer Loop 'perform a find connected trace to get a set of results 'QI for the INetElements interface on the current network Set pNetElements = pGeometricNetwork.Network 'get a valid junction EID, and create a junction flag object for this lngJunctionEID = 0 Do If pNetElements.IsValidElement(lngJunctionEID, esriETJunction) Then Exit Do Else lngJunctionEID = lngJunctionEID + 1 End If Loop 'get the feature class ID, feature ID and sub ID for this network element pNetElements.QueryIDs lngJunctionEID, esriETJunction, lngUserClassID, lngUserID, lngUserSubID 'create a junction flag for this junction Set pJunctionFlag = New esriNetworkAnalysis.JunctionFlag With pJunctionFlag .UserClassID = lngUserClassID .UserID = lngUserID .UserSubID = lngUserSubID End With 'create a TraceFlowSolver object and set the junction flag as the origin Set pTraceFlowSolver = New esriNetworkAnalysis.TraceFlowSolver Set pNetSolver = pTraceFlowSolver Set pNetSolver.SourceNetwork = pNetElements pTraceFlowSolver.PutJunctionOrigins 1, pJunctionFlag 'get the results of a find connected trace pTraceFlowSolver.FindFlowElements esriFMConnected, esriFEJunctionsAndEdges, pJunctionResults, pEdgeResults With pNetworkAnalysisExtResults 'determine whether complex edge elements are rendered using the DrawComplex property blnDrawComplex = .DrawComplex 'specify that individual elements of complex edges are drawn using the DrawComplex property blnDrawComplex = True .DrawComplex = blnDrawComplex 'determine whether the results are returned as drawings or as selections blnResultsAsSelection = .ResultsAsSelection If blnResultsAsSelection Then 'select the results .CreateSelection pJunctionResults, pEdgeResults 'results are selected, not drawn -- so the drawing count is zero lngNumResultsInDrawing = 0 'get the number of selected features lngNumFeaturesSelected = pMap.SelectionCount 'clear the map selection pMap.ClearSelection Else 'draw the results .SetResults pJunctionResults, pEdgeResults 'get the number of network elements drawn in the results lngNumResultsInDrawing = .ResultFeatureCount 'get the number of selected features lngNumFeaturesSelected = pMap.SelectionCount 'clear the results using the ClearResults method .ClearResults End If End With 'remove all of the networks from the extension lngNetworkCount = pNetworkAnalysisExt.NetworkCount For i = 0 To lngNetworkCount - 1 Set pGeometricNetwork = pNetworkAnalysisExt.CurrentNetwork pNetworkAnalysisExt.DeleteNetwork pGeometricNetwork Next i 'remove all of the feature layers from the map lngLayerCount = pMap.LayerCount For i = 0 To lngLayerCount - 1 Set pFeatureLayer = pMap.Layer(0) pMap.DeleteLayer pFeatureLayer Next i
[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
in the upper-left corner of the page.