GEOG 485:
GIS Programming and Software Development

Lesson 1 Practice Exercise 4 Solution

PrintPrint

Solution:

import arcpy

fc = "C:/PSU/geog485/USA/USA.gdb/Boundaries"

desc = arcpy.Describe(fc)
shapeType = desc.shapeType

print ("The geometry type of " + fc + " is " + shapeType)

Explanation:

This script begins like the one in example 1.6.2 since both require using the Describe function. As mentioned in the exercise instructions, you can see that the Describe function provides access to a spatialReference property by looking at the Describe function's help page for Datasets. In other words, if the object you're describing is a type of Dataset, it has a spatialReference property.

In this case, you were asked to determine the geometry type of a feature class and given the hint that the property you need belongs to objects of the type FeatureClass. This hint should have led you to click the FeatureClass properties link on the Describe function's Help page and scan through the list of properties until you found shapeType. The solution above reads the shapeType property, stores the return value in a variable, and then inserts that value into a user-friendly print message that also includes the name of the feature class.