ネットワーク データセットにソースを追加

Public Sub AddSource()

On Error GoTo Error:

    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument

    Dim pMap As IMap
    Set pMap = pMxDocument.FocusMap
    
    'レイヤ
    Dim pNetworkLayer As INetworkLayer
    Set pNetworkLayer = pMxDocument.FocusMap.Layer(0)
    
    Dim pNetworkDataset As INetworkDataset
    Set pNetworkDataset = pNetworkLayer.NetworkDataset
    
    Dim pDatasetComponent As IDatasetComponent
    Set pDatasetComponent = pNetworkDataset
    
    'ネットワーク データセット用のソース作成
    Dim pNetworkSource As INetworkSource
    Set pNetworkSource = New JunctionFeatureSource  'ソースの種類
    pNetworkSource.Name = "Point"   'フィーチャクラス名
    pNetworkSource.ElementType = esriNetworkElementType.esriNETJunction 'ソースの種類
    
    Dim pJunctionFeatureSource As IJunctionFeatureSource
    Set pJunctionFeatureSource = pNetworkSource
    pJunctionFeatureSource.UsesSubtypes = False
    pJunctionFeatureSource.RemoveAllClassConnectivityGroups
    pJunctionFeatureSource.AddClassConnectivityGroup (1)
    pJunctionFeatureSource.ClassConnectivityPolicy = esriNetworkJunctionConnectivityPolicy.esriNJCPHonor

        
    Dim pNetworkBuild As INetworkBuild
    Set pNetworkBuild = pNetworkDataset
    
    pNetworkBuild.AddSource pNetworkSource
    
    MsgBox "Done"
    
    Exit Sub
    
Error:
    
    Debug.Print Err.Number, Err.Description

End Sub