YouTube | Facebook | X(Twitter) | RSS

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上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『"地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

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