Show Navigation | Hide Navigation

Describing data in a geoprocessing script

Release 9.1
Last modified September 14, 2005
E-mail This Topic Printable Version Give Us Feedback


Related Topics

Geoprocessing tools work with all types of data, such as geodatabase feature classes, shapefiles, rasters, tables, topologies, and networks. Each piece of data has properties that may be used to control the flow of a script or the parameters of a tool. For example, the output feature type of an intersect operation is dependent on the type of data being intersected. When the Intersect tool is run within a script on a list of input datasets, it must be able to determine the data types used so the correct output type can be set.
Using the geoprocessor's Describe method, a dataset's properties may be determined and used to make decisions.
The Describe method
Learn more about the Describe method
Describe creates what is known as a Dispatch object. Its properties are dynamic, depending on what data type is described. These properties come from the data elements defined by the geoprocessing COM framework. See the Data Elements Object Diagram found in the ArcGIS  Developer Help system for more information. The output of Describe is an object containing properties, such as data type, fields, indices, and so on. Different dataset types have different properties, so the object created by Describe changes its properties depending on what is being described.

# Import COM Dispatch and create geoprocessor
from win32com.client import Dispatch
GP = Dispatch("esriGeoprocessing.GpDispatch.1")

# Describe feature class
desc = GP.Describe("D:/St_Johns/data.mdb/roads")
type = desc.FeatureType


The following charts show the properties available for each data type. Any feature class will have the standard feature class properties shown in the first chart below. This includes geodatabase, shapefile, coverage, CAD, Vector Product Format, and Smart Data Compression feature classes.
Feature Class properties Feature Class properties

Coverage feature classes always exist within a coverage dataset. Some of the coverage feature class properties stem from this relationship.
Coverage FeatureClass properties Coverage Feature Class properties

Layers and table views are used to limit the features/rows from the underlying data source. This is done using a where clause to define an initial set of features, a selection, or both. The FieldInfo property is used to set what fields are available and what their names are.
Layer properties Layer properties

TableView properties TableView properties

Datasets are containers that define the spatial reference and extents of their contents. Coverages, geodatabase feature datasets, and CAD datasets are all examples of this.
Dataset properties Dataset properties

All simple tables in the geodatabase require an ObjectID (OID) type field. It uniquely identifies each object stored in the table in the database. Other table types, such as INFO or dBASE, do not require an OID field.
Relationship Class properties Relationship Class properties
Table properties Table properties

Shapefile, personal geodatabase, and coverage workspaces have no connection properties. Domains are only found in Access and ArcSDE workspaces, as domains are only found in geodatabases.
Workspace properties Workspace properties

Fields and indexes

The fields or indexes property of a table or feature class is exposed as an enumeration. In this case, the enumeration may contain field or index objects, consisting of properties for each field or index. The ListFields and ListIndexes methods may be used to create the same enumerations or limit their contents. The following example shows how to create an enumeration of fields and how to loop through the contents to find a specific field.

# Import COM Dispatch and create geoprocessor
from win32com.client import Dispatch
GP = Dispatch("esriGeoprocessing.GpDispatch.1")

# Describe feature class
fc = "D:/St_Johns/data.mdb/roads"
desc = GP.Describe(fc)
fields = desc.Fields
field = fields.next()
while field:
    if field.Name == "Flag":
         # Set the value for the field and exit loop
	GP.CalculateField(fc, "Flag", "1")
        break
    field = fields.next()


The properties of the field and index objects are listed below:
Field properties Field object properties

Index object properties Index object properties

ListFields and ListIndexes may be used to limit the results based in name and type.
Learn more about ListFields and ListIndexes

The spatial reference object

Geographic datasets, such as feature classes, coverages, and rasters, have a spatial reference, which defines a dataset's coordinate system, x,y domain, m domain, and z domain. Each part of the spatial reference has a number of properties, especially the coordinate system, which defines what map projection options are used to define horizontal coordinates. All this information is available from the spatial reference property, which is actually another object containing a number of properties.

CreateObject method

Learn more about the CreateObject method

# Describe feature class
fc = "D:/St_Johns/data.mdb/roads"
desc = GP.Describe(fc)
# Get the spatial reference 
SR = desc.SpatialReference
# Check if the feature class is in projected space
if SR.Type == "Projected":
    GP.Copy(fc,"D:/St_Johns/data.mdb/UTM")


The properties of the spatial reference object are listed below:

The spatial reference object properties

Learn more about projected and geographic coordinate systems and ellipsoids

Property sets

Some properties are composed of a set of values. The tolerances of a coverage or the connection properties of a workspace are examples of this. Property sets have named properties that can be called from the property set itself. In the example below, the tolerances of a coverage are printed to the standard output:

from win32com.client import Dispatch
GP = Dispatch("esriGeoprocessing.GpDispatch.1")

desc = GP.Describe("D:/St_Johns/freshwater")
covTols = desc.tolerances
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 of an enterprise geodatabase workspace will 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. Refer to ArcObjects documentation for more information about workspace properties.

Checking for existence

Scripts often use paths to data, which may be problematic if the data being referenced does not exist. Data may be deleted or moved between executions of a script, which will cause errors if the path is used as a geoprocessing tool parameter. If there is a possibility of a referenced dataset not existing during a script's execution, the geoprocessor's Exists method should be used.
The Exists method
Learn more about the Exists method
The function simply returns a Boolean value for the existence of a dataset or object at the time of execution. Objects, such as a cursor, spatial reference, or any other object managed by the geoprocessor, may also be used as input to Exists. Exists will work with any type of data available in ArcCatalog or with any system file or folder. An ArcCatalog path must be used for this and any other method of the geoprocessor when referring to GIS data. If the data resides in an enterprise geodatabase, the name must be fully qualified.

GP.Workspace = "D:/St_Johns/data.mdb"
# Clip roads feature class if it exists
fc = "D:/St_Johns/data.mdb/roads"
if GP.Exists(fc):
   GP.clip_analysis(fc,"urban_area","urban_roads")


The default behavior for all tools is to overwrite any output that already exists. This behavior may be changed by changing the overwrite data setting to false. An error is returned when the overwrite data setting is false and a tool's specified output already exists.
Learn more about working with geodatabases and qualifying names

Please visit the Feedback page to comment or give suggestions on ArcGIS Desktop Help.
Copyright © Environmental Systems Research Institute, Inc.