I am stumped on how to create an interface using either a Custom or a Python toolbox that will allow a user to input a list of raster layers and a selected field from each raster. It seems as though a value table is the way to go, but although this works for feature layers, it apparently does not work for raster layers.
As illustrated in the following code snippet from a python toolbox and the resulting screenshot, you can have a parameter that takes a single raster layer and another that takes a field with a dependency between the two, and you get a picklist of raster attributes as expected (provided the raster has an attribute table). And, using a value table to input multiple feature classes, you also get the expected picklist of attributes for each feature class. But you do not get the picklist using a value table with raster layers, as shown in the screen shot.
This value table functionality for feature layer/field pairs has apparently been around since Pro v 2.4 (according to this post by @DrewFlater -- https://community.esri.com/t5/python-questions/python-toolbox-value-table-with-list/m-p/546572/highl...) - is there a plan to extend this to rasters as well? (or am I just missing something here?)
In the absence of having this functionality available using value tables, does anyone have ideas on how to accomplish this seemingly simple task -- i.e., a way for a user to enter a list of raster/field pairs? Any insights would be greatly appreciated - thank you!
class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Value Table Test"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
# Param0 is raster layer
param0 = arcpy.Parameter(
displayName = "Raster #1",
name="Raster1",
datatype="Raster Layer",
parameterType="Optional",
direction="Input")
# Param1 is raster field
param1 = arcpy.Parameter(
displayName = "Raster #1 field",
name="Raster1_field",
datatype="Field",
parameterType="Optional",
direction="Input")
param1.parameterDependencies = [param0.name]
#param2 is a value table of feature layers & fields
param2 = arcpy.Parameter(
displayName = "Feature Layers",
name="Feature_list",
datatype="GPValueTable",
parameterType="Optional",
direction="Input")
param2.columns = [["GPFeatureLayer", "Feature Layer"], ["Field", "Field Name"]]
#param3 is a value table of raster layers and fields
param3 = arcpy.Parameter(
displayName = "Raster Layers",
name="Raster_list",
datatype="GPValueTable",
parameterType="Optional",
direction="Input")
param3.columns = [["GPRasterLayer", "Raster Layer"], ["Field", "Field Name"]]
params = [param0, param1, param2, param3]
return params
Solved! Go to Solution.
I've confirmed what @ChrisRingo describes above. When using a value table with feature layer and field pairs, the field column automatically receives a dependency on the feature layer column. When using a value table with raster layer and field pairs, this dependency is not achieved and does not appear like it can be forced. This is a defect that we will correct in a future release.
There is not a workaround possible that I'm aware of at this time.
I've confirmed what @ChrisRingo describes above. When using a value table with feature layer and field pairs, the field column automatically receives a dependency on the feature layer column. When using a value table with raster layer and field pairs, this dependency is not achieved and does not appear like it can be forced. This is a defect that we will correct in a future release.
There is not a workaround possible that I'm aware of at this time.
Thanks much for confirming.
One other thing I forgot to mention - if you type in a valid field name - i.e., one that exists in the attribute table - the tool will accept it. Conversely, it will throw an error if you type in a field name that doesn't exist in the table.