Skip to main content

FieldInfo

汇总

提供图层和表视图的字段信息方法和属性。

讨论

当对象用作地理处理工具的输入时, FieldInfo 对象不支持字段重命名。

语法

FieldInfo()

属性

名称 说明 数据类型

count

(只读)

字段计数。

Integer

方法

addField(field_name, new_field_name, visible, split_rule)

添加字段信息条目

名称 说明 数据类型

field_name

The field name from the input feature class or table.

String

new_field_name

The field name for the new layer or table view.

String

visible

Specifies whether the field will be visible or hidden.

  • VISIBLE—The field will be visible.

  • HIDDEN—The field will be hidden.

String

split_rule

Specifies the behavior of an attribute's values when a feature is split.

  • NONE—The attributes of the two resulting features will take on a copy of the original value.

  • RATIO—The attributes of resulting features will be a ratio of the original feature's value. The ratio is based on the division of the original geometry. If the geometry is divided equally, each new feature's attribute will get one-half of the value of the original object's attribute.

String

exportToString()

将对象导出至其字符串表示。

返回值

数据类型 说明

String

对象的字符串表示。

findFieldByName(field_name)

按字段名查找字段索引。

名称 说明 数据类型

field_name

The field name that will be used to find its index position.

String

返回值

数据类型 说明

Integer

索引位置。

findFieldByNewName(field_name)

按新字段名查找字段索引。

名称 说明 数据类型

field_name

The new field name that will be used to find its index position.

String

返回值

数据类型 说明

Integer

索引位置。

getFieldName(index)

按索引位置获取表中的字段名称。

名称 说明 数据类型

index

The index position.

Integer

返回值

数据类型 说明

String

字段名称。

getNewName(index)

按索引位置返回表中的新字段名称。

名称 说明 数据类型

index

The index position.

Integer

返回值

数据类型 说明

String

新字段名称。

getSplitRule(index)

按索引位置获取表中的分割规则。

名称 说明 数据类型

index

The index position.

String

返回值

数据类型 说明

String

分割规则。

  • NONE—The attributes of the two resulting features will take on a copy of the original value.

  • RATIO—The attributes of resulting features will be a ratio of the original feature's value. The ratio is based on the division of the original geometry. If the geometry is divided equally, each new feature's attribute will get one-half of the value of the original object's attribute.

getVisible(index)

按索引位置从表中返回可见标记。

名称 说明 数据类型

index

The index position.

String

返回值

数据类型 说明

String

可见标记。

  • VISIBLE—The field will be visible.

  • HIDDEN—The field will be hidden.

loadFromString(string)

通过已格式化字符串定义 FieldInfo 对象。

名称 说明 数据类型

string

The string representation of the object.

In addition to FieldInfo methods and properties, you can also construct a FieldInfo object from a formatted string.

Each field is defined by four space-delimited values. Fields are separated by a semicolon.

  • The name of the input field.

  • The name of the output field (not currently supported).

  • Sets whether the field is visible or hidden.

    • VISIBLE—The field is visible.

    • HIDDEN—The field is hidden.

  • Sets the behavior of an attribute's values when a feature is split.

    • NONE—The attributes of the two resulting features take on a copy of the original value.

    • RATIO—The attributes of resulting features are a ratio of the original feature's value. The ratio is based on the division of the original geometry. If the geometry is divided equally, each new feature's attribute gets one-half of the value of the original object's attribute.

import arcpy
field_info_str = "fieldA fieldA VISIBLE NONE;fieldB fieldB HIDDEN RATIO"
field_info = arcpy.FieldInfo()
field_info.loadFromString(field_info_str)

String

removeField(index)

从表中移除 FieldInfo 条目。

名称 说明 数据类型

index

The index position of the FieldInfo object.

Integer

setFieldName(index, field_name)

在表中设置字段名称。

名称 说明 数据类型

index

The index position.

Integer

field_name

The field name that will be set in the table.

String

setNewName(index, new_field_name)

设置表中的新字段名。

注:

setNewName 方法更新对象中的字段名时,如果使用 FieldInfo 对象作为地理处理工具的输入,则不会应用名称更改。

名称 说明 数据类型

index

The index position.

None

new_field_name

The new field name that will be set in the table.

String

setSplitRule(index, rule)

在表中设置分割规则。

名称 说明 数据类型

index

The index position.

Integer

rule

Specifies the split rule that will be set in the table.

  • NONE—The attributes of the two resulting features will take on a copy of the original value.

  • RATIO—The attributes of resulting features will be a ratio of the original feature's value. The ratio is based on the division of the original geometry. If the geometry is divided equally, each new feature's attribute will get one-half of the value of the original object's attribute.

String

setVisible(index, visible)

设置表中字段的可见策略。

名称 说明 数据类型

index

The index position.

Integer

visible

Specifies the visible policy that will be set in the table.

  • VISIBLE—The field will be visible.

  • HIDDEN—The field will be hidden.

String

代码示例

FieldInfo 示例

显示要素图层的 FieldInfo 对象属性。

import arcpy

feature_class = "c:/Data/wells.shp"
layer = "temp_layer"
arcpy.management.MakeFeatureLayer(feature_class, layer)

# Create a describe object
desc = arcpy.Describe(layer)

# Access Describe's fieldInfo property
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(f"Field Name: {field_info.getFieldName(index)}")
    print(f"\tSplit Rule: {field_info.getSplitRule(index)}")
    print(f"\tVisible:    {field_info.getVisible(index)}")