gpf.tools.fieldutils module

The fields module contains helper functions related to working with Esri Fields (GIS attributes).

gpf.tools.fieldutils.FIELDTYPE_MAPPING = {'Blob': 'BLOB', 'Date': 'DATE', 'Double': 'DOUBLE', 'Guid': 'GUID', 'Integer': 'LONG', 'Raster': 'RASTER', 'Single': 'FLOAT', 'SmallInteger': 'SHORT', 'Text': 'TEXT'}

Lookup dictionary to map Field types to the field types used in ArcPy’s AddField() function.

gpf.tools.fieldutils.clone_field(field)[source]

Returns a deep copy (clone) of a Field object.

Parameters:field (arcpy.Field) – The Field instance that should be cloned.
Return type:arcpy.Field
gpf.tools.fieldutils.list_fields(obj, names_only=True, uppercase=False)[source]

Returns a list of (modified) Field objects or field names for a given list of Field objects or a dataset.

Parameters:
  • obj (list, str, unicode) – Dataset path or list of original Field instances.
  • names_only (bool) – When True (default), a list of field names instead of Field instances is returned.
  • uppercase (bool) – When True (default=``False``), the returned field names will be uppercase. This also applies when names_only is set to return Field instances.
Returns:

List of field names or Field instances.

Return type:

list

gpf.tools.fieldutils.missing_fields(table, expected_fields)[source]

Returns a list of missing field names for a specified table or feature class. The expected field names are case-insensitive. If an empty list is returned, all fields are accounted for.

If one ore more expected field names are a “special field” (containing an ‘@’ sign), these will be resolved to the actual field names. If this process fails, the field will be considered missing.

Parameters:
  • table (str, unicode) – The table or feature class for which to check the fields.
  • expected_fields (list, tuple) – A list of fields that should be present in the table or feature class.
Return type:

list

gpf.tools.fieldutils.add_field(dataset, name, template_field=None, alias=None)[source]

Adds a new field to a dataset, based off a template_field Field instance. All properties from the new field will be taken from this template field, except for the name (and alias).

Parameters:
  • dataset (str, unicode) – The full path to the dataset (table, feature class) to which the field should be added.
  • name (str, unicode) – The name of the field to add.
  • template_field (Field) – An optional template Field on which the new field should be based. If no template field is specified, a default field of type TEXT is created.
  • alias (str, unicode) – An optional alias name for the field. Defaults to None.
Return type:

Result

Raises:

ValueError – If a template field was provided, but it’s not a Field instance, or if the template field is of an unsupported type (i.e. GlobalID, OID or Geometry).