FieldInfo

摘要

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

说明

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

语法

 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)

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

removeField (index)

从表中移除 FieldInfo 条目。

setFieldName (index, field_name)

将字段名称设置到表中。

setNewName (index, new_field_name)

设置表中的新字段名。

注:

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

setSplitRule (index, rule)

将分割规则设置到表中。

setVisible (index, visible)

设置表中字段的可见标记。

方法

addField (field_name, new_field_name, visible, split_rule)
参数说明数据类型
field_name

输入要素类或表中的字段名称。

String
new_field_name

设置新图层或表视图的字段名称。

String
visible

将字段设置为可见或隐藏。

  • VISIBLE字段可见。
  • HIDDEN字段隐藏。
String
split_rule

分割要素时,设置属性值的行为。

  • NONE两个生成要素的属性采用原始值的副本。
  • RATIO两个所生成要素的属性是原始要素值的比率。该比率取决于原始几何的分割。如果几何被分割成相等的两部分,则每个新要素的属性值将是原始对象属性值的一半。
String
exportToString ()
返回值
数据类型说明
String

对象的 WKT 字符串表示。

findFieldByName (field_name)
参数说明数据类型
field_name

用于查找字段索引位置的字段名

String
返回值
数据类型说明
Integer

索引位置

findFieldByNewName (field_name)
参数说明数据类型
field_name

用于查找新字段索引位置的新字段名。

String
返回值
数据类型说明
Integer

索引位置。

getFieldName (index)
参数说明数据类型
index

The index position.

Integer
返回值
数据类型说明
String

字段名称。

getNewName (index)
参数说明数据类型
index

The index position.

Integer
返回值
数据类型说明
String

新字段名称。

getSplitRule (index)
参数说明数据类型
index

索引位置。

String
返回值
数据类型说明
String

分割规则。

  • NONE两个生成要素的属性采用原始值的副本。
  • RATIO两个所生成要素的属性是原始要素值的比率。该比率取决于原始几何的分割。如果几何被分割成相等的两部分,则每个新要素的属性值将是原始对象属性值的一半。
getVisible (index)
参数说明数据类型
index

The index position.

String
返回值
数据类型说明
String

可见标记。

  • VISIBLE字段可见。
  • HIDDEN字段隐藏。
loadFromString (string)
参数说明数据类型
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)
参数说明数据类型
index

The index position of the FieldInfo object.

Integer
setFieldName (index, field_name)
参数说明数据类型
index

索引位置。

Integer
field_name

要设置到表中的字段名称。

String
setNewName (index, new_field_name)
参数说明数据类型
index

The index position.

None
new_field_name

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

String
setSplitRule (index, rule)
参数说明数据类型
index

索引位置。

Integer
rule

要设置到表中的分割规则。

  • NONE两个生成要素的属性采用原始值的副本。
  • RATIO两个所生成要素的属性是原始要素值的比率。该比率取决于原始几何的分割。如果几何被分割成相等的两部分,则每个新要素的属性值将是原始对象属性值的一半。
String
setVisible (index, visible)
参数说明数据类型
index

索引位置。

Integer
visible

要设置到表中的可见策略。

  • VISIBLE字段可见。
  • 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)}")

相关主题