ArcCatalog でフォルダー内のフィーチャクラスを再帰検索

投稿日:2016/9/1 (木) 更新日:

'ArcCatalogでフォルダ内のフィーチャクラスを再帰検索
Public Sub GetFeatureClasses()
 
    Dim pGxApplication As IGxApplication
    Dim pGxObject As IGxObject
     
    Set pGxApplication = Application
    Set pGxObject = pGxApplication.SelectedObject
     
    If TypeOf pGxObject Is IGxFolder Then
     
        Dim pGxObjectContainer As IGxObjectContainer
        Set pGxObjectContainer = pGxObject
         
        Dim pEnumGxObject As IEnumGxObject
        Set pEnumGxObject = pGxObjectContainer.Children
         
        GetFeatureClass pEnumGxObject
    Else
        MsgBox "カタログ ツリーでフォルダを選択してください。", vbInformation
    End If
    
End Sub
 
'再帰関数
Private Function GetFeatureClass(EnumGxObject As IEnumGxObject)
     
    EnumGxObject.Reset
     
    Dim pGxObject As IGxObject
    Set pGxObject = EnumGxObject.Next
     
    Do Until pGxObject Is Nothing
     
        If TypeOf pGxObject Is IGxObjectContainer Then
            Dim pGxObjectContainer As IGxObjectContainer
            Set pGxObjectContainer = pGxObject
             
            If Not pGxObjectContainer.Children Is Nothing Then
                GetFeatureClass pGxObjectContainer.Children '再帰
            End If
         
        End If
         
        If TypeOf pGxObject Is IGxDataset Then
            Dim pGxDataset  As IGxDataset
            Set pGxDataset = pGxObject
            If pGxDataset.Type = esriDTFeatureClass Then
                Call RunTheFunction(pGxObject)
            End If
        End If
 
        Set pGxObject = EnumGxObject.Next
          
    Loop
 
End Function
 
Private Function RunTheFunction(GxDataset As IGxDataset)
    Debug.Print GxDataset.Dataset.Name
End Function

関連記事

  • この記事を書いた人

羽田 康祐

伊達と酔狂でエクストリーム スポーツに挑む GIS エンジニア。 GIS、IT、趣味に関して日々の出来事で学んだ記憶を記録するためにブログを書いています。同じ問題に出会った方の参考になっていただければ幸いです。GIS を使った自己紹介はこちら

-プログラミング, ArcGIS
-,

Copyright© WINGFIELD since1981 , 2019 All Rights Reserved.