Many geoprocessing tools have input parameters that accept more than one value. For example, the multiring buffer tool accepts multiple buffer distances, the delete field tool accepts multiple fields that can be deleted, and there are many other examples. In this recipe, you will learn how to create a ValueTable
object that serves as multivalue input to a tool.
There are three ways to specify a multivalue parameter: as a Python list, a string with each value separated by semicolons, or an ArcPy ValueTable
object. In this recipe, we're going to take a look at how to specify mutlivalue input parameters by using ValueTable
.
Follow these steps to learn how to use a ValueTable
to submit multiple values to a tool:
ValueTable.py
.arcpy
and set the workspace:import arcpy arcpy.env.workspace = r"c:ArcyBookdata"
ValueTable
object:import arcpy arcpy.env.workspace = r"c:ArcyBookdata" vTab = arcpy.ValueTable()
5
, 10
, and 20
:vTab = arcpy.ValueTable() vTab.setRow(0, "5") vTab.setRow(1, "10") vTab.setRow(2, "20")
dist
) is created as a reference to the ValueTable
, which you have already created:vTab = arcpy.ValueTable() vTab.setRow(0, "5") vTab.setRow(1, "10") vTab.setRow(2, "20") inFeature = 'Hospitals.shp' outFeature = 'HospitalMBuff.shp' dist = vTab bufferUnit = "meters"
MultipleRingBuffer
tool and pass the variables as parameters:inFeature = 'Hospitals.shp' outFeature = 'HospitalMBuff.shp' dist = vTab bufferUnit = "meters" arcpy.MultipleRingBuffer_analysis(inFeature, outFeature, dist, bufferUnit, '', 'ALL') print("Multi-Ring Buffer Complete")
C:ArcpyBookcodeCh12ValueTable.py
solution file.
ValueTable
is a simple virtual table that you can use as input to tools that accept multiple values. In this recipe, we created a ValueTable
object, added three values, and then passed this object into the MultipleRingBuffer
tool. The MultipleRingBuffer
tool used this information to create new polygon layers based on the buffer distances provided in the ValueTable
object.