Scripting Your ArcGIS Geoprocessing Tasks (Part 1)

Posted on February 5, 2008. Filed under: ESRI, Geoprocessing | Tags: , , , , |

This week I’ll be starting a new series of posts covering the use of  scripting for the automation of ArcGIS geoprocessing tasks.  In particular we’ll be covering the use of the Python language to automate many of your common tasks.  In this first post we’ll take a look at the Geoprocessor Object Model Diagram.  Before you can begin scripting your geoprocessing tasks with any language you need to have a fundamental understanding of the objects you’ll be working with and how the interrelate.

An Object Model Diagram graphically portrays the classes, methods, properties, and events that are available in the class library as well as the interrelationships between the objects.  This is a high level document that allows you to research the functionality available on each class.  You can think of the Geoprocessor object model diagram as a blueprint for writing ArcGIS geoprocessing scripts.  In this diagram, notice that each class is color coded by functionality.  For example, the Geoprocessor (arcgisscripting/GpDispatch) class is a cyan color.  This is not always the case as the ArcObjects OMDs are not color coded. 

Click here to see a demonstration of the functionality contained on the Geoprocessor OMD.

OMD Symbology
Let’s discuss some of the symbols that you will see when looking at the object model diagram.  Each class is represented with a colored box that helps group the objects by functional category.  The class name is listed at the top of the box.  Below, the GpDispatch or arcgisscripting class is shown in a cyan color.

Class Properties are symbolized by barbells.  Some properties have a single barbell while others have two.  A single barbell represents a read only property whereas a double barbell represents a property that is read-write.  Read-write properties allow you to change the existing value of a property by assigning a value.  Read only property only allow you to read the current value stored in the property.

Class Methods are represented as arrows on the object model diagram.  Methods are actions that an object performs, and can optionally take arguments.  For example, the Describe(InputValue) takes an input value that represents a path to a dataset and performs the action of returning an object containing descriptive information about the dataset.

Geoprocessor Object (also called GpDispatch or arcgisscripting
The Geoprocessor object, also known by its technical names, GpDispatch and arcgisscripting, is the highest level object in the Geoprocessor library.  This object is the entry point for writing all geoprocessing scripts in Python, and can be used to accomplish many GIS tasks.  The Geoprocessor object has many methods and properties some of which are dynamic.  All geoprocessing tools (i.e. Buffer, Merge, Dissolve, etc) are dynamic methods found on Geoprocessor.  Because they are so numerous and dependent upon the software license level in use, these methods are not included on the object model diagram.  For example, the Buffer Tool is a frequently used tool in ArcGIS, but no reference to this tool is found on the Geoprocessor OMD.  Instead, the OMD has a reference to Dynamic Methods and Properties found at the bottom of the GpDispatch object.  The dynamic Tool(tool parameters) method is a generic reference to all tools currently available at your ArcGIS license level. 

Because it is the entry point for all geoprocessing tasks you must obtain a reference to GpDispatch in each geoprocessing script that you write.  To access this object you must follow a two step process.  Below you will see a code example of this process using both the ArcGIS 9.2 native module and the dispatch method (pre ArcGIS 9.2).  Since ArcObjects was built on the COM protocol and Python supports COM through the win32com.client module, you must first import the Python module, and this is what the first line of each script accomplishes.  The second step of the process creates the Geoprocessor object.  This is accomplished through the create( ) method on arcgisscripting or the Dispatch method on win32com.client.

We’ll have more to say about this object in coming posts.

Cursor Objects
I have covered cursor objects previously, and will repost this to the blog in the near future.  For now I’ll briefly state that cursors are in-memory objects that contain records from a Table or Feature Class.  Three types of cursors exist: search, insert, and update.  Search cursors are created for read-only access to records.  Insert cursors are used to insert new records, and update cursors are used to update or delete data.  We’ll cover cursors in much greater detail in a coming post.

Enumeration Objects (Lists Methods)
Enumeration objects hold lists of some type of object.  This list could includes the fields or indexes available on a feature class or table or simply a list of all the raster datasets within a given workspace.  As you will see there are a number of enumeration methods available in the geoprocessing framework.

As their name implies, List methods on Geoprocessor are used to create lists of various objects (fields, indexes, datasets, feature classes, rasters, tables, etc).  Here are the list methods available on Geoprocessor for creating these enumeration objects.

Describe Objects
The Describe method on GpDispatch is used to obtain detailed information about your data including data type, name, spatial reference, and many others.  This method returns a describe object containing descriptive information about the data type.  For instance, calling the Describe( ) method on a Feature Class would return a FeatureClass object.  This object is often used to test for the type of data (either point, line, or polygon) before further processing.  Various read-only properties are available through this object including ShapeType which returns the basic data type such as point, line, or polygon, ShapeFieldName, Fields, and Extent. 

Miscellaneous Objects
The Geoprocessor OMD contains a number of additional miscellaneous objects including SpatialReference, FieldMappings, FieldMap, Result and a few others.  We’ll cover these objects in a future post.

More Information
As you may have read, we will be presenting a new Virtual GIS Classroom course, “GIS Programming 101: Mastering Python for Geoprocessing in ArcGIS” starting March 24th and ending April 18th.

About these ads

Make a Comment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

2 Responses to “Scripting Your ArcGIS Geoprocessing Tasks (Part 1)”

RSS Feed for GeoChalkboard Comments RSS Feed

Thanks to going through the “Geoprocessing Python Scripts in ArcGIS” course last week. I know what the heck you’re talking about.

[...] Scripting your geoprocessing tasks (Part 1), (Part 2), (Part 3) from [...]


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...

Follow

Get every new post delivered to your Inbox.

Join 46 other followers

%d bloggers like this: