Query classes
Available with Spatial Analyst license.
You may want to identify an individual argument that was used in a parameter and, based on that value, perform a specific set of functions. The following sections provide the rules for querying the arguments for Spatial Analyst classes.
Classes created with a fixed number of inputs
To query the value of an argument in a class object, you can access the property of the object.
circle = NbrCircle(5, "CELL") # varRadius will be assigned the radius property (which is 5) varRadius = circle.radiusYou can inspect the value of an object or an object property.
>>> circle = NbrCircle(5, "CELL") >>> print(circle) Circle 5 Cell >>> print(circle.radius) 5
Classes created from lists or list of lists
To view the entire remap table, you can use the Python
printfunction.>>> remap = RemapValue([[1, 11], [2, 12], [3, 13]]) >>> print(remap) 1 11; 2 12; 3 13 >>> print(remap.remapTable) [[1, 11], [2, 12], [3, 13]]To query an individual entry in the list for class objects that are created from lists within lists, identify the list the entry is in and address the location of the entry in that list.
>>> remap = RemapValue([[1, 11], [2, 12], [3, 13]]) >>> print(remap.remapTable[1][1]) 12
Classes created from a series of classes in a list
To query an individual x- or y-coordinate or the x,y coordinates of a point in a list for a class object that was created from a series of classes in a list, access the property of the individual class in the input series.
>>> points = [Point(0, 5), Point(15, 175), Point(225, 450)] >>> # The following statement queries the x value of the second input point >>> xvalue = points[1].X >>> print(xvalue) 15.0
Type determination
To determine the type of a class object, use the Python
typefunction.>>> neighborhood = NbrCircle(5, "CELL") >>> neighType = type(neighborhood) >>> print(neighType) <class 'arcpy.sa.ParameterClasses.NbrCircle'>To compare types, use the Python
isinstancefunction.circle = NbrCircle(5, "CELL") # The general format is: isinstance(AnyObject, AnyClass) # In the following statement, val will be assigned True val = isinstance(circle, NbrCircle) # In the following statement, val will be assigned False val = isinstance(circle, NbrRectangle)