After a long delay, it is time for the third installment of understanding the Geoprocessor Programming Model that will deal with the Describe object. If you missed the last two parts, feel free to look at them first (Part 1: understanding what the geoprocessor is, and Part 2: accessing data with the geoprocessor). As always, comments are welcomed and encouraged.
As mentioned earlier, the geoprocessor gives us the ability to access or create data to perform various operations. These operation vary in type and content, but more often than not are performed on data we are not intimately familiar with. This can become a problem quite quickly, as we need to know the names of fields in the datasets, as well as other characteristics (the type of data we are dealing with, spatial references, geographical extent and other). The solution to this lack of knowledge comes through the describe object which provides users with methods to identify all unknown information beforehand. In the most basic form of usage, one uses the describe object on a dataset, accessing the bottom left box in the diagram, the Describe Object Properties. The Python code to achieve this follows:
import arcgisscripting # Import the module provided by ESRI gp = arcgisscripting.create(9.3) # Create the geoprocessor object dataset = r"c:\data\testData.shp" # The location of the data. This is usually # not hardcoded but discovered with List methods dsc = gp.Describe(dataset) # Create a describe object for the dataset print dsc.DataType # Print the data type of our dataset print dsc.CatalogPath # Print the path to the dataset
With the above simple example, we managed to read the Data Type and Catalog Path of a dataset. While this seems simple, it can become a very powerful tool, when on considers the possible return values (listed below).
| Return Value | Data Type |
| FeatureDataset | Containers for data that include spatial reference and extent of contents. |
| FeatureClass | Feature class in a geodatabase, a shapefile if standalone. |
| Table | A geodatabase or standalone table. |
| RelationshipClass | A geodatabase class storing relationships. |
| RasterDataset | A raster dataset type. |
| RasterBand | A raster band. |
| RasterCatalog | A raster catalog. |
| Workspace | A workspace as defined by ESRI (directory or database). |
As you can see, the return values as listed above correspond to different objects in our diagram (the boxes in the first image above). This means that it would be trivial for us to move between the first access we have into the Describe realm (through the Describe object) and move to any other box of our choice when we are not familiar with what possible data we have.
Retrieving Information about data: Feature Classes
The most commonly used types of data in GIS now seems to be feature classes, either standalone (in the form of shapefiles) or in a geodatabase. As such, we will use the example of a feature class to retrieve information about out data. This is of course not the only type of data one can use, so please refer to the image on the top for more information.
As you can see from the diagram on the left, feature classes have specific information associated with them, including what feature type they are of, their shape type, and the shape field name we used in part two of this series. We will dive right into it by trying to identify what shape type our feature class has, and what type of feature it is.
import arcgisscripting # Import the module provided by ESRI gp = arcgisscripting.create(9.3) # Create the geoprocessor object dataset = r"c:\data\testData.shp" # The location of the data. This is usually # not hardcoded but discovered with List methods dsc = gp.Describe(dataset) # Create a describe object for the dataset # As we know the dataset is of type FeatureClass, # all the properties of the FeatureClass object # are available to us now. print dsc.ShapeType # Print what type of shape we have # (point, polygon, polyline, etc) print dsc.FeatureType # Print what type of features are stored # (simple, annotation, dimension, etc)
With the above code we can identify what type of shape we have and the type of feature stored. For possible values to these properties, please check this help file.
In the FeatureClass Properties object image above, on the bottom, you can see that there are also Table Properties and Dataset Properties listed. This means that when you have a feature class, you automatically gain access to those properties as well (as a feature class has them embedded). Therefore, we can use this to our advantage to further retrieve information about our feature class, like the name of all fields within the feature class. The example below shows you how to achieve this.
import arcgisscripting
# Import the module provided by ESRI
gp = arcgisscripting.create(9.3)
# Create the geoprocessor object
data = r"c:\data\testData.shp"
# The location of the data. This is usually
# not hardcoded but discovered with List methods
dsc = gp.Describe(data)
# Create a describe object for the data
# As we know the dataset is of type FeatureClass,
# all the properties of the FeatureClass object
# and inherited objects are available to us now.
dataFlds = dsc.Fields
# Retrieve a list of fields in the table of the
# feature class as a Python list. Note the fields
# are of Field Object type.
for fld in dataFields:
print fld.Name
What he have done on the above example is run the ListFields() method mentioned in an older article (Using the Geoprocessor’s List Methods). Similarly, one can follow the Dataset Properties object (shown on your right) to access information like the extent of the data, or the spatial reference system. Don’t forget, both of those return an object, which has a corresponding box in the geoprocessor programming model diagram, so you need to treat them as such.
In this installment, I have shown you how one can use the Describe object the geoprocessor makes available to us to retrieve information about our data. While I did not provide complete examples of every single possible option available, hopefully by reading this post you are able to navigate your options better to achieve your goals.
As always, comments are encouraged and I am willing to answer any questions you may have.
Related posts:




