Describing data

Geoprocessing tools work with all types of data, such as geodatabase feature classes, shapefiles, rasters, tables, topologies, and networks. Each piece of data has particular properties that can be accessed and used to control the flow of a script or used as the parameters of a tool. For example, the output feature type of the Intersect tool is dependent on the shape type of the data being intersected—point, line, or polygon. When the Intersect tool is run within a script on a list of input datasets, you must be able to determine the shape types of the input datasets so the correct output shape type can be set. You can use the Describe function to determine the shape types of all the input datasets.

Using the Describe function, a dataset's properties can be determined and used to make decisions. For instance, in the following example, the script uses Describe to evaluate the shape type (polyline, polygon, point, and so on) of input data and determine which geoprocessing tool is appropriate.

import arcpy

inFC = arcpy.GetParameterAsText(0)
outFC = arcpy.GetParameterAsText(1)

# Describe a feature class
#
desc = arcpy.Describe(inFC)

# Get the shape type (Polygon, Polyline) of the feature class
#
type = desc.shapeType

# If the shapeType is Polygon convert the data to polylines using the FeatureToLine tool,
#  otherwise just copy the data using the CopyFeatures tool.
#
if type == "Polygon":
    arcpy.FeatureToLine_management(inFC, outFC)
else:
    arcpy.CopyFeatures_management(inFC, outFC)

    
 

The Describe function returns a Describe object, with multiple properties, such as data type, fields, indexes, and many others. Its properties are dynamic, meaning that depending on what data type is described, different describe properties will be available for use.

Describe properties are organized into a series of property groups. Any particular dataset will acquire the properties of at least one of these groups. For instance, if describing a geodatabase feature class, you could access properties from the GDB FeatureClass, FeatureClass, Table, and Dataset property groups. All data, regardless of the data type, will always acquire the generic Describe Object properties.

Describe Object PropertiesArcInfo Item PropertiesArcInfo Table PropertiesCAD Drawing Dataset PropertiesCAD FeatureClass PropertiesCoverage FeatureClass PropertiesCoverage PropertiesDataset PropertiesdBase Table PropertiesFeatureClass PropertiesFile PropertiesFolder PropertiesGDB FeatureClass PropertiesGDB Table PropertiesGeometric Network PropertiesLayer PropertiesMap Document PropertiesMosaic Dataset PropertiesNetwork Analyst Layer PropertiesNetwork Dataset PropertiesPrj File PropertiesRaster Band PropertiesRaster Catalog PropertiesRaster Dataset PropertiesRelationshipClass PropertiesRepresentationClass PropertiesSchematic Dataset PropertiesSchematic Diagram PropertiesSchematic Folder PropertiesSDC FeatureClass PropertiesShapefile FeatureClass PropertiesTable PropertiesTableView PropertiesText File PropertiesTin PropertiesTool PropertiesToolbox PropertiesTopology PropertiesVPF Coverage PropertiesVPF FeatureClass PropertiesVPF Table PropertiesWorkspace Properties

Working with property sets

Some properties are members of a Property set. For example, the tolerances of a coverage or the connection properties of a workspace are returned as Property sets. Property sets have named properties that can be called from the property set itself. In the example below, the tolerances of a coverage (Fuzzy, Dangle, TicMatch, Edit, NodeSnap, Weed, Grain, and Snap) are printed to the standard output:

import arcpy

# Create a describe object from a coverage feature class
#
desc = arcpy.Describe("D:/St_Johns/covs/freshwater")

# Create a property set of coverage tolerances
#
covTols = desc.tolerances

# Print each coverage tolerance
#
print covTols.fuzzy
print covTols.dangle
print covTols.ticMatch
print covTols.edit
print covTols.nodeSnap
print covTols.weed
print covTols.grain
print covTols.snap

Property sets are typically used when the properties of the object being described vary. The connection properties (server, instance, database, user, and version) of an enterprise geodatabase workspace vary depending on the type of ArcSDE database that is being used, so it is well suited to a property set that has no predefined set of values.

Related Topics


12/15/2011