gpf.tools.metadata module

The metadata module contains functions and classes that help describe data.

exception gpf.tools.metadata.DescribeWarning[source]

Bases: RuntimeWarning

The warning type that is shown when ArcPy’s arcpy.Describe() failed.

class gpf.tools.metadata.Describe(element)[source]

Bases: object

Wrapper class for the ArcPy Describe object that exposes the most commonly used properties.

If ArcPy’s arcpy.Describe() failed, a warning will be shown but no errors will be (re)raised. Any Describe property that is retrieved, will return None in this case.

If a property does not exist, it will also return None. If this is not desired, consider using the get() function, which behaves similar to a dict.get() and can return a user-defined default value if the property was not found.

Params:

  • element (object):

    An object, name, or path of an element for which to retrieve its metadata.

Note

Only a limited amount of properties has been exposed in this class. For a complete list of all possible properties, please have a look here. For these unlisted properties, the same rule applies: if it doesn’t exist, None is returned. If another return value is required, use get().

get(name, default=None) → Any[source]

Returns the value of a Describe object attribute by name, returning default when it has not been found. This method does not show warnings or raise errors if the attribute does not exist.

Parameters:
  • name – The name of the property.
  • default – The default value to return in case the property was not found.
num_rows(where_clause: Union[str, gpf.tools.queries.Where, None] = None) → int[source]

Returns the number of rows for a table or feature class.

If the current Describe object does not support this action or does not have any rows, 0 will be returned.

Parameters:where_clause (str, gpf.tools.queries.Where) – An optional where clause to base the row count on.
dataType

Returns the data type for this Describe object. All Describe objects should have this property. If it returns None, the object has not been successfully retrieved.

datasetType

Returns the name of the dataset type (e.g. Table, FeatureClass etc.). If the described object is not a dataset, None is returned.

shapeType

Returns the geometry type for this Describe object. This will return ‘Polygon’, ‘Polyline’, ‘Point’, ‘Multipoint’ or ‘MultiPatch’ if the described object is a feature class, or None if it’s not.

fields

Returns a list of all Field objects (attributes) for this Describe object. If the described object is not a dataset, this will return an empty list.

indexes

Returns a list of all Index objects (attribute indexes) for this Describe object. If the described object is not a dataset, this will return an empty list.

get_fields(names_only: bool = True, uppercase: bool = False) → List[Union[str, arcpy.arcobjects.arcobjects.Field]][source]

Returns a list of all fields in the described object (if any).

Parameters:
  • names_only – When True (default), a list of field names instead of Field instances is returned.
  • uppercase – 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.

editable_fields(names_only: bool = True, uppercase: bool = False) → List[Union[str, arcpy.arcobjects.arcobjects.Field]][source]

For data elements that have a fields property (e.g. Feature classes, Tables and workspaces), this will return a list of all editable (writable) fields.

Parameters:
  • names_only – When True (default), a list of field names instead of Field instances is returned.
  • uppercase – 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.

extent

Returns an Extent object for this Describe element. If the described object is not a feature class, this will return an empty Extent.

spatialReference

Returns a SpatialReference object for this Describe element. If the described object is not a feature class, this will return an empty SpatialReference.

isVersioned

Returns True if the Describe element refers to a versioned dataset. If the described object is not a dataset or not versioned, this will return False.

is_pointclass

Returns True if the described object is a Point feature class.

is_multipointclass

Returns True if the described object is a Multipoint feature class.

Return type:bool
is_polylineclass

Returns True if the described object is a Polyline feature class.

is_polygonclass

Returns True if the described object is a Polygon feature class.

is_multipatchclass

Returns True if the described object is a MultiPatch feature class.

is_featureclass

Returns True if the described object is a feature class.

is_featuredataset

Returns True if the described object is a feature dataset.

is_geometricnetwork

Returns True if the described object is a geometric network.

is_mosaicdataset

Returns True if the described object is a mosaic dataset (raster).

is_rasterdataset

Returns True if the described object is a raster dataset.

is_table

Returns True if the described object is a table.

hasZ

Returns True if the described object is Z aware (i.e. is 3D). If the object is not a feature class or not Z aware, False is returned.

hasM

Returns True if the described object is M aware (i.e. has measures). If the object is not a feature class or not M aware, False is returned.

globalIDFieldName

Global ID field name. Returns None if the field is missing or if the Describe object is not a dataset.

OIDFieldName

Object ID field name. Returns None if the field is missing or if the Describe object is not a dataset.

shapeFieldName

Perimeter or polyline length field name. Returns None if the field is missing or if the Describe object is not a dataset.

lengthFieldName

Perimeter or polyline length field name. Returns None if the field is missing or if the Describe object is not a dataset.

areaFieldName

Polygon area field name. Returns None if the field is missing or if the Describe object is not a dataset.

rasterFieldName

Raster field name. Returns None if the field is missing or if the Describe object is not a dataset.

subtypeFieldName

Subtype field name. Returns None if the field is missing or if the Describe object is not a dataset.