限定的字段名(环境设置)

遵循“限定的字段名”环境的工具将使用此设置来区分限定的字段名和未限定的字段名。限定的字段名是要素类或表中的这样一些字段名称,在它们自身的名称后会附加原始要素类或表的名称。仅使用连接数据时,此才会涉及此设置。

用法说明

当工具参数中包含字段映射时(“转换”工具箱的许多工具中都包括),字段名自动设置为 UNQUALIFIED,因此无需设置该环境。

对话框语法

脚本语法

arcpy.env.qualifiedFieldNames = qualified_field_names

qualified_field_names

说明

True

输出字段名将包括表名。这也可以使用 QUALIFIED 关键字设置。这是默认设置。

False

输出字段名将不包括表名。这也可以使用 UNQUALIFIED 关键字设置。

qualifiedFieldNames 语法
# Name: addjoin.py
# Purpose: Join a table to a featureclass and have the output
#          unqualified
# Author: ESRI

# 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)
    
    # Copy the layer to a new permanent feature class
    # Output fields are unqualified, so the field name will 
    # not contain the origin table
    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

相关主题

5/10/2014