gpf.tools.metadata module

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

exception gpf.tools.metadata.DescribeWarning[source]

Bases: exceptions.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)[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 (str) – The name of the property.
  • default – The default value to return in case the property was not found.
num_rows(where_clause=None)[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, unicode, gpf.tools.queries.Where) – An optional where clause to base the row count on.
Return type:int
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.

Return type:unicode
datasetType

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

Return type:unicode
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.

Return type:unicode
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.

Return type: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.

Return type:list
get_fields(names_only=True, uppercase=False)[source]

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

Parameters:
  • 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

get_editable_fields(names_only=True, uppercase=False)[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 (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

extent

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

Return type:arcpy.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.

Return type:arcpy.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.

Return type:bool
is_pointclass

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

Return type:bool
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.

Return type:bool
is_polygonclass

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

Return type:bool
is_multipatchclass

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

Return type:bool
is_featureclass

Returns True if the described object is a feature class.

Return type:bool
is_featuredataset

Returns True if the described object is a feature dataset.

Return type:bool
is_geometricnetwork

Returns True if the described object is a geometric network.

Return type:bool
is_mosaicdataset

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

Return type:bool
is_rasterdataset

Returns True if the described object is a raster dataset.

Return type:bool
is_table

Returns True if the described object is a table.

Return type:bool
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.

Return type:bool
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.

Return type:bool
globalIDFieldName

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

Return type:unicode
OIDFieldName

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

Return type:unicode
shapeFieldName

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

Return type:unicode
lengthFieldName

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

Return type:unicode
areaFieldName

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

Return type:unicode
rasterFieldName

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

Return type:unicode
subtypeFieldName

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

Return type:unicode