添加连接 (Data Management)

许可等级:BasicStandardAdvanced

摘要

基于公用字段将图层连接到另一图层或表(其中图层是指带有栅格属性表的要素图层、表视图或栅格图层)。

连接表中的记录与输入图层名称中的记录相匹配。输入连接字段值与输出连接字段值相等时,即表示匹配。此连接是临时性连接。

插图

Add Join

用法

语法

AddJoin_management (in_layer_or_view, in_field, join_table, join_field, {join_type})
参数说明数据类型
in_layer_or_view

连接表将连接的图层或表视图。

Mosaic Layer; Raster Catalog Layer; Raster Layer; Table View
in_field

连接基于的输入图层或表视图中的字段。

Field
join_table

将连接到输入图层或表视图的图表或表视图。

Mosaic Layer; Raster Catalog Layer; Raster Layer; Table View
join_field

连接表中的字段,包含连接将基于的值。

Field
join_type
(可选)

指定如何处理输入中与连接表中的记录相匹配的记录。

  • KEEP_ALL输入图层或表视图中的所有记录都将包含在输出中,也称为外部连接。这是默认设置。
  • KEEP_COMMON只有输入中那些与连接表中行相匹配的记录才会显示在结果中,也称为内部连接。
Boolean

代码实例

添加连接 (AddJoin) 示例 1(Python 窗口)

以下 Python 窗口脚本演示了如何在即时模式下使用 AddJoin 函数。

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.MakeFeatureLayer_management ( "Habitat_Analysis.gdb/vegtype", "veg_layer")
arcpy.AddJoin_management( "veg_layer", "HOLLAND95", "vegtable.dbf", "HOLLAND95")
arcpy.CopyFeatures_management( "veg_layer", "Habitat_Analysis.gdb/vegjoin")
添加连接 (AddJoin) 示例 2(独立脚本)

该独立脚本显示了作为工作流一部分的 AddJoin 函数,用于将表连接到要素类,然后提取所需要素。

# Name: AttributeSelection.py
# Purpose: Join a table to a featureclass and select the desired attributes

# Import system modules
import arcpy
from arcpy import env

try:
    # Set environment settings
    env.workspace = "C:/data"
    env.qualifiedFieldNames = False
    
    # Set local variables    
    inFeatures = "Habitat_Analysis.gdb/vegtype"
    layerName = "veg_layer"
    joinTable = "vegtable.dbf"
    joinField = "HOLLAND95"
    expression = "vegtable.HABITAT = 1"
    outFeature = "Habitat_Analysis.gdb/vegjoin"
    
    # Create a feature layer from the vegtype featureclass
    arcpy.MakeFeatureLayer_management (inFeatures,  layerName)
    
    # Join the feature layer to a table
    arcpy.AddJoin_management(layerName, joinField, joinTable, joinField)
    
    # Select desired features from veg_layer
    arcpy.SelectLayerByAttribute_management(layerName, "NEW_SELECTION", expression)
    
    # Copy the layer to a new permanent feature class
    arcpy.CopyFeatures_management(layerName, outFeature)
    
except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message

环境

相关主题

许可信息

ArcGIS for Desktop Basic:是
ArcGIS for Desktop Standard:是
ArcGIS for Desktop Advanced:是
9/15/2013