基于此示例,这是一个ArcObjects方法,用于枚举层上的所有联接并列出其目标和源表名称以及主键和外键:
- 获得对
ILayer
具有一个或多个联接的的引用
- 投放
ILayer
到IDisplayTable
- 将
IDisplayTable.DisplayTable
属性投放到IRelQueryTable
- 当前表是
IRelQueryTable
:
- 检查
RelQueryTable
的DestinationTable
和SourceTable
属性
- 检查
OriginPrimaryKey
和OriginForeignKey
的性能IRelQueryTable.RelationshipClass
特性。
- 将当前表设置为current
RelQueryTable
的SourceTable
属性
此Python脚本(使用comtypes和此helper模块)将从最新到最早遍历所有联接,并为每个联接打印目标和源表名称,原始主键和原始外键:
from ESRICOMHelpers import * # helper module from https://gis.stackexchange.com/a/5082/753
esriArcMapUI = GetESRIModule("esriArcMapUI")
esriCarto = GetESRIModule("esriCarto")
esriGeoDatabase = GetESRIModule("esriGeoDatabase")
def listJoins(table):
while CType(table, esriGeoDatabase.IRelQueryTable):
relQueryTable = CType(table, esriGeoDatabase.IRelQueryTable)
destTable = relQueryTable.DestinationTable
sourceTable = relQueryTable.SourceTable
destDataset = CType(destTable, esriGeoDatabase.IDataset)
sourceDataset = CType(sourceTable, esriGeoDatabase.IDataset)
relClass = relQueryTable.RelationshipClass
print destDataset.Name, sourceDataset.Name, relClass.OriginPrimaryKey, relClass.OriginForeignKey
table = sourceTable
if __name__ == "__main__":
#app = GetCurrentApp() # Use if run in-process
app = GetApp("ArcMap") # Use if run in a standalone script
mxd = CType(app.Document, esriArcMapUI.IMxDocument)
# Gets the first layer in the active data frame
map = mxd.FocusMap
lyr = map.Layer[0]
# Need to get the "display table" to access the joins
displayTable = CType(lyr, esriCarto.IDisplayTable).DisplayTable
# List the layer's joined tables
listJoins(displayTable)
输出示例,给定具有三个联接的源层:
join_table_3 master_fc_join_table_1_join_table_2 JOIN_ID_3 master_fc.MASTER_ID
join_table_2 master_fc_join_table_1 JOIN_ID_2 master_fc.MASTER_ID
join_table_1 master_fc JOIN_ID_1 MASTER_ID
有关更多信息,请参见如何从Python访问ArcObjects?