FieldInfo

Resumen

Provides field info methods and properties for layer and table views.

Debate

The FieldInfo object does not support the renaming of fields when the object is used as input to a geoprocessing tool.

Sintaxis

 FieldInfo  ()

Propiedades

PropiedadExplicaciónTipo de datos
count
(Sólo lectura)

The field count.

Integer

Descripción general del método

MétodoExplicación
addField (field_name, new_field_name, visible, split_rule)

Adds a field info entry

exportToString ()

Exports the object to its string representation.

findFieldByName (field_name)

Finds the field index by field name

findFieldByNewName (field_name)

Finds the field index by new field name.

getFieldName (index)

Gets the field name from the table by index position.

getNewName (index)

Returns the new field name from the table by index position.

getSplitRule (index)

Gets the split rule from the table by index position.

getVisible (index)

Returns the visible flag from the table by index position.

loadFromString (string)

Defines a FieldInfo object from a formatted string.

removeField (index)

Removes a FieldInfo entry from a table.

setFieldName (index, field_name)

Sets the field name into the table.

setNewName (index, new_field_name)

Sets a new field name in the table.

Nota:

While the setNewName method updates a field name in the object, the name change will not be applied when the FieldInfo object is used as input to a geoprocessing tool.

setSplitRule (index, rule)

Sets the split rule into the table.

setVisible (index, visible)

Set the visible flag of a field on the table.

Métodos

addField (field_name, new_field_name, visible, split_rule)
ParámetroExplicaciónTipo de datos
field_name

The field name from the input feature class or table.

String
new_field_name

Sets the field name for the new layer or table view.

String
visible

Sets whether the field is visible or hidden.

  • VISIBLEField is visible.
  • HIDDENField is hidden.
String
split_rule

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

  • NONEThe attributes of the two resulting features take on a copy of the original value.
  • RATIOThe 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.
String
exportToString ()
Valor de retorno
Tipo de datosExplicación
String

The WKT string representation of the object.

findFieldByName (field_name)
ParámetroExplicaciónTipo de datos
field_name

The field name used to find its index position

String
Valor de retorno
Tipo de datosExplicación
Integer

The index position

findFieldByNewName (field_name)
ParámetroExplicaciónTipo de datos
field_name

The new field name used to find its index position.

String
Valor de retorno
Tipo de datosExplicación
Integer

The index position.

getFieldName (index)
ParámetroExplicaciónTipo de datos
index

The index position.

Integer
Valor de retorno
Tipo de datosExplicación
String

The field name.

getNewName (index)
ParámetroExplicaciónTipo de datos
index

The index position.

Integer
Valor de retorno
Tipo de datosExplicación
String

The new field name.

getSplitRule (index)
ParámetroExplicaciónTipo de datos
index

The index position.

String
Valor de retorno
Tipo de datosExplicación
String

The split rule.

  • NONEThe attributes of the two resulting features take on a copy of the original value.
  • RATIOThe 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.
getVisible (index)
ParámetroExplicaciónTipo de datos
index

The index position.

String
Valor de retorno
Tipo de datosExplicación
String

The visible flag.

  • VISIBLEField is visible.
  • HIDDENField is hidden.
loadFromString (string)
ParámetroExplicaciónTipo de datos
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)
ParámetroExplicaciónTipo de datos
index

The index position of the FieldInfo object.

Integer
setFieldName (index, field_name)
ParámetroExplicaciónTipo de datos
index

The index position.

Integer
field_name

The field name to set into the table.

String
setNewName (index, new_field_name)
ParámetroExplicaciónTipo de datos
index

The index position.

None
new_field_name

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

String
setSplitRule (index, rule)
ParámetroExplicaciónTipo de datos
index

The index position.

Integer
rule

The split rule to set into the table.

  • NONEThe attributes of the two resulting features take on a copy of the original value.
  • RATIOThe 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.
String
setVisible (index, visible)
ParámetroExplicaciónTipo de datos
index

The index position.

Integer
visible

The visible policy to set into the table.

  • VISIBLEField is visible.
  • HIDDENField is hidden.
String

Muestra de código

FieldInfo example

Display FieldInfo object properties for a feature layer.

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)}")

Temas relacionados