Field (arcpy)

摘要

字段对象表示表中的列。字段有许多属性,最常用的是其名称和类型。

讨论

可通过 ListFields 和 Describe 功能访问字段属性。

更新字段属性时仅会更新字段对象,而不会更改表或要素类中的实际字段。

语法

Field ()

属性

属性说明数据类型
aliasName
(读写)

字段的别名。

String
baseName
(读写)

非限定字段名称。

String
domain
(读写)

关联属性域的名称。

String
editable
(读写)

可编辑状态:字段可编辑时为真。

Boolean
isNullable
(读写)

可为空状态:字段允许空值时为 True。

Boolean
length
(读写)

字段的长度。

Integer
name
(读写)

字段的名称。

String
precision
(读写)

字段精度。

Integer
required
(读写)

必填状态:字段必须包含值时为 True。

Boolean
scale
(读写)

字段的小数位数。

Integer
type
(读写)

字段类型。

  • Blob —Blob
  • 日期 —日期
  • 双精度 —双精度
  • 几何 —几何
  • Guid —Guid
  • 整型 —整型(长整型)
  • OID —对象 ID
  • 栅格 —栅格
  • 单精度 —单精度(浮点型)
  • SmallInteger —小整型(短整型)
  • 字符串 —字符串(文本)

了解有关 ArcGIS 字段数据类型的详细信息

注注:

字段对象的 type 属性与添加字段工具的 field_type 参数列出的选项不完全匹配。要允许添加字段工具使用所有类型关键字,需映射以下字段类型:整型至 LONG、字符串至 TEXT 以及 SmallInteger 至 SHORT。

String

代码实例

字段示例

显示指定要素类的字段属性。

import arcpy

feature_class = "c:/data/counties.shp"

# Create a list of fields using the ListFields function
fields = arcpy.ListFields(feature_class)

# Iterate through the list of fields
for field in fields:
    # Print field properties
    print("Field:       {0}".format(field.name))
    print("Alias:       {0}".format(field.aliasName))
    print("Type:        {0}".format(field.type))
    print("Is Editable: {0}".format(field.editable))
    print("Required:    {0}".format(field.required))
    print("Scale:       {0}".format(field.scale))
    print("Precision:   {0}".format(field.precision))

相关主题

5/10/2014