YouTube | Facebook | X(Twitter) | RSS

テーブル結合を解除する方法

2016/9/1 (木)

'How to remove all joins from a layer or table in ArcMap
'http://help.arcgis.com/en/sdk/10.0/vba_desktop/conceptualhelp/index.html#//000100000096000000
 
Public Sub RemoveAllJoins()
     
    On Error GoTo EH
     
    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pDoc.FocusMap
     
    ' Get the selected layer or table
    Dim pSelItem As IUnknown
    Set pSelItem = pDoc.SelectedItem
    If pSelItem Is Nothing Then
        MsgBox "Nothing is selected in the table of contents"
        Exit Sub
    End If
    If Not (TypeOf pSelItem Is ILayer Or TypeOf pSelItem Is IStandaloneTable) Then
        MsgBox "A layer or table must be selected."
        Exit Sub
    End If
     
    Dim pDispRC As IDisplayRelationshipClass
    Set pDispRC = pSelItem
     
    ' Remove all joins
    If pDispRC.RelationshipClass Is Nothing Then
        MsgBox "The layer or table is not joined."
        Exit Sub
    End If
     
    pDispRC.DisplayRelationshipClass Nothing, esriLeftInnerJoin
     
    Exit Sub
EH:
     
    MsgBox Err.Number & "  " & Err.Description
     
 
 
'http://edndoc.esri.com/arcobjects/9.0/Samples/Tables/Remove_the_last_join_from_a_layer_or_table_in_ArcMap.htm
'How to remove the last join from a layer or table in ArcMap
Public Sub RemoveLastJoin()
     
    ' Get the map
    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pDoc.FocusMap
     
    ' Get the selected layer or table
    Dim pSelItem As IUnknown
    Set pSelItem = pDoc.SelectedItem
    If Not TypeOf pSelItem Is IDisplayTable Then
        MsgBox "No Feature layer or table selected"
        Exit Sub
    End If
     
    ' Make sure the selected layer is joined
    Dim pDispTable As IDisplayTable
    Dim pTable As ITable
    Set pDispTable = pSelItem
    Set pTable = pDispTable.DisplayTable
    If Not TypeOf pTable Is IRelQueryTable Then
        MsgBox "The layer or table is not joined"
        Exit Sub
    End If
     
    ' Get the source table of the current join
    ' object (RelQueryTable)
    Dim pRelQTab As IRelQueryTable
    Set pRelQTab = pTable
    Set pTable = pRelQTab.SourceTable
     
    ' UnJoin
    Dim pDispRC As IDisplayRelationshipClass
    Dim pRQTInfo As IRelQueryTableInfo
    Set pDispRC = pSelItem
    ' If more than one table had been joined, replace
    ' the current join with the previous join
    If TypeOf pTable Is IRelQueryTable Then
        Set pRelQTab = pTable
        Set pRQTInfo = pRelQTab
        pDispRC.DisplayRelationshipClass pRelQTab.RelationshipClass, pRQTInfo.JoinType
        ' If one table has been joined, remove all joins
    Else
        pDispRC.DisplayRelationshipClass Nothing, esriLeftInnerJoin
    End If
     
End Sub
  • この記事を書いた人

羽田 康祐

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

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