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, uppercase=False)[source]¶ Retrieves the field name from a
Field
instance and optionally changes it to uppercase.Parameters: - field (arcpy.Field) – An
arcpy.Field
instance. - uppercase (bool) – When
True
(default =False
), the returned name will be made uppercase.
Return type: unicode
- field (arcpy.Field) – An
-
gpf.tools.fieldutils.
list_fields
(obj, names_only=True, uppercase=False)[source]¶ Returns a list of 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 ofField
instances is returned. - uppercase (bool) – 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.Return type: list
- obj (list, str, unicode) – Dataset path or list of original
-
gpf.tools.fieldutils.
list_missing
(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).