描述
为图层和表视图提供字段信息方法和属性。
语法
FieldInfo ()
属性
| 属性 | 说明 | 数据类型 | 
| count (只读) | The field count. | Integer | 
方法概述
| 方法 | 说明 | 
| addField (field_name, new_field_name, visible, split_rule) | 添加字段条目信息 | 
| exportToString () | 将对象导出至其字符串表示。 | 
| findFieldByName (field_name) | 按字段名查找字段索引 | 
| findFieldByNewName (field_name) | 按新字段名查找字段索引。 | 
| getFieldName (index) | 按索引位置获取表中的字段名称。 | 
| getNewName (index) | 按索引位置获取表中的新字段名称。 | 
| getSplitRule (index) | 按索引位置获取表中的分割规则。 | 
| getVisible (index) | 按索引位置从表中获取可见标记。 | 
| loadFromString (string) | 使用对象的字符串表示来恢复对象。可以使用 exportToString 方法创建字符串表示。 | 
| removeField (index) | 从表中移除字段信息条目。 | 
| setFieldName (index, field_name) | 将字段名称设置到表中。 | 
| setNewName (index, new_field_name) | 将新字段名称设置到表中。 | 
| setSplitRule (index, rule) | 将分割规则设置到表中。 | 
| setVisible (index, visible) | 设置表中字段的可见标记。 | 
方法
addField (field_name, new_field_name, visible, split_rule)
| 参数 | 说明 | 数据类型 | 
| field_name | 输入要素类或表中的字段名称。 | String | 
| new_field_name | 设置新图层或表视图的字段名称。 | String | 
| visible | 将字段设置为可见或隐藏。 
 | String | 
| split_rule | 分割要素时,设置属性值的行为。 
 | String | 
exportToString ()
返回值
| 数据类型 | 说明 | 
| String | 对象的字符串表示。 | 
findFieldByName (field_name)
| 参数 | 说明 | 数据类型 | 
| field_name | 用于查找字段索引位置的字段名 | String | 
返回值
| 数据类型 | 说明 | 
| Integer | 索引位置 | 
findFieldByNewName (field_name)
| 参数 | 说明 | 数据类型 | 
| field_name | 用于查找新字段索引位置的新字段名。 | String | 
返回值
| 数据类型 | 说明 | 
| Integer | 索引位置。 | 
getFieldName (index)
| 参数 | 说明 | 数据类型 | 
| index | 索引位置。 | Integer | 
返回值
| 数据类型 | 说明 | 
| String | 字段名称。 | 
getNewName (index)
| 参数 | 说明 | 数据类型 | 
| index | 索引位置。 | Integer | 
返回值
| 数据类型 | 说明 | 
| String | 新字段名称。 | 
getSplitRule (index)
| 参数 | 说明 | 数据类型 | 
| index | 索引位置。 | String | 
返回值
| 数据类型 | 说明 | 
| String | 分割规则。 
 | 
getVisible (index)
| 参数 | 说明 | 数据类型 | 
| index | 索引位置。 | String | 
返回值
| 数据类型 | 说明 | 
| String | 可见标记。 
 | 
loadFromString (string)
| 参数 | 说明 | 数据类型 | 
| string | 对象的字符串表示。 | String | 
removeField (index)
| 参数 | 说明 | 数据类型 | 
| index | 字段信息对象的索引位置。 | Integer | 
setFieldName (index, field_name)
| 参数 | 说明 | 数据类型 | 
| index | 索引位置。 | Integer | 
| field_name | 要设置到表中的字段名称。 | String | 
setNewName (index, new_field_name)
| 参数 | 说明 | 数据类型 | 
| index | 索引位置。 | None | 
| new_field_name | 要设置到表中的新字段名称。 | String | 
setSplitRule (index, rule)
| 参数 | 说明 | 数据类型 | 
| index | 索引位置。 | Integer | 
| rule | 要设置到表中的分割规则。 
 | String | 
setVisible (index, visible)
| 参数 | 说明 | 数据类型 | 
| index | 索引位置。 | Integer | 
| visible | 要设置到表中的可见策略。 
 | String | 
代码示例
FieldInfo 示例
显示要素图层的 FieldInfo 属性。
import arcpy
feature_class = "c:/Data/wells.shp"
layer = "temp_layer"
arcpy.MakeFeatureLayer_management(feature_class, layer)
# Create a describe object
desc = arcpy.Describe(layer)
# If a feature layer, continue
if desc.dataType == "FeatureLayer":
    # Create a fieldinfo object
    field_info = desc.fieldInfo
    # Use the count property to iterate through all the fields
    for index in range(0, field_info.count):
        # Print fieldinfo properties
        print("Field Name: {0}".format(field_info.getFieldName(index)))
        print("\tNew Name:   {0}".format(field_info.getNewName(index)))
        print("\tSplit Rule: {0}".format(field_info.getSplitRule(index)))
        print("\tVisible:    {0}".format(field_info.getVisible(index)))