gpf.tools.fieldutils module¶
The fields module contains helper functions related to working with Esri Fields (GIS attributes).
See also
The gpf.tools.metadata.Describe
class has a gpf.tools.metadata.Describe.get_fields()
and a gpf.tools.metadata.Describe.get_editable_fields()
function, which might also be helpful.
-
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’sAddField()
function.
-
gpf.tools.fieldutils.
get_name
(field: arcpy.arcobjects.arcobjects.Field, uppercase: bool = False) → str[source]¶ Retrieves the field name from a
Field
instance and optionally changes it to uppercase.Parameters: - field – An
arcpy.Field
instance. - uppercase – When
True
(default =False
), the returned name will be made uppercase.
- field – An
-
gpf.tools.fieldutils.
list_fields
(obj: Sequence, names_only: bool = True, uppercase: bool = False) → List[Union[str, arcpy.arcobjects.arcobjects.Field]][source]¶ Returns a list of Field objects or field names for a given list of Field objects or a dataset.
Parameters: - obj – Dataset path or list of original
Field
instances. - names_only – When
True
(default), a list of field names instead ofField
instances is returned. - uppercase – When
True
(default=``False``), the returned field names will be uppercase. This does not apply when names_only isFalse
andField
instances are returned.
Returns: List of field names or
Field
instances.- obj – Dataset path or list of original
-
gpf.tools.fieldutils.
list_missing
(table: str, expected_fields: Sequence[str]) → Sequence[str][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 – The table or feature class for which to check the fields.
- expected_fields – A list of fields that should be present in the table or feature class.
-
gpf.tools.fieldutils.
has_field
(table: str, field_name: str) → bool[source]¶ Simple wrapper for the
list_missing()
function to check if a single field exists.Parameters: - table –
- field_name –
Returns:
-
gpf.tools.fieldutils.
add_field
(dataset: str, name: str, template_field: [<class 'arcpy.arcobjects.arcobjects.Field'>, None] = None, alias: [<class 'str'>, None] = None) → arcpy.arcobjects.arcobjects.Result[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 – The full path to the dataset (table, feature class) to which the field should be added.
- name – The name of the field to add.
- template_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 – An optional alias name for the field. Defaults to
None
.
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).