Examples of using iterators in ModelBuilder
For
To understand the use of the For tool, see the illustration below, where the For iterator iterates from a value of 500 to a value of 2000, increasing by increments of 500. The output of For is used as the Buffer Distance parameter in the Buffer tool and in the output name as in-line variable substitution.
Iterate Feature Selection
To understand the use of Iterate Feature Selection in ModelBuilder, see the illustration below, where the model calculates how much of the East Coast land-cover map area was destroyed by a 100-meter swath of five category 1 hurricanes. The Input Feature variable is a feature class of five Atlantic hurricane paths with a 100-meter buffer around it. The Input Raster variable is a land-cover raster.
In this example, the name of the hurricane has been used as a grouping field to make the selection, and the selected feature is used as the input for the Zonal Statistics As Table tool to generate an output table with statistics on the land cover destroyed during the hurricanes' landfall.
The Iterate Feature Selection tool has two outputs:
- Selected feature (connected as input to the Zonal Statistics As Table tool).
- The Value variable, which contains the name of the feature (based on the grouping field) used as an in-line variable in the output name of the Output Table variable.
Iterate Row Selection
To understand the use of Iterate Row Selection in ModelBuilder, see the illustration below, where the model creates a deviational ellipse for theft incidents during different periods of the day—morning, afternoon, evening, and night—to detect an underlying pattern of crime.
The Input Feature Class variable is a feature class containing vandalism incident points. It contains the field Crime_Peri (crime period), which is the time of day the incident occurred (the strings Morning, Afternoon, Evening, and Night). This field is used as the grouping field to make the selection, and the selected rows are used to create an output standard deviational ellipse.
The tool has two outputs:
- The Row Selection variable containing the selected rows for a unique crime period. These rows are input to the Directional Distribution (Standard Deviational Ellipse) tool.
- The Value variable, which contains the value of the grouping field (Morning, Afternoon, Evening, or Night). This value is used as an in-line variable in the output name of the Output Standard Deviational Ellipse variable.
Iterate Field Values
To understand the use of Iterate Field Values in ModelBuilder, see the illustration below, where the model runs Cluster And Outlier Analysis for the number of people below the poverty line in each county to compare the results at different distances. These distances are recorded as the Distance field in the Input Table variable.
Note that on the Iterate Field Values dialog box, the Unique Values option is checked by default to iterate over each unique value in a table. Unchecking the Unique Values option will iterate for each value in the field, and the output value will be repeated if there are duplicate values in the input field.
Iterate Field Values has one output: the value of the field, which is used as the Distance Band or Threshold distance parameter of the Cluster And Outlier Analysis tool. The Value variable is also used to construct the output file name of the Output Cluster Feature Class variable with the use of in-line variable substitution.
Iterate Multivalue
To understand the use of Iterate Multivalue in ModelBuilder, see the illustration below, where the model changes the map projection of several feature classes stored in different drives and workspaces. The projected output feature classes are written to a single output database.
The tool has one output: the value, which is a string of feature classes connected to the Project tool as input.
Iterate Datasets
To understand the use of Iterate Datasets in ModelBuilder, see the illustration below, where the model copies all the feature datasets contained in the Input Dataset variable, a workspace variable. The iteration has been restricted to iterate only on the FEATURE dataset type.
The tool has two outputs:
- Dataset (Landbase and Water).
- Name, which is used as the in-line variable %Name% in the output of the Copy tool.
Iterate Feature Classes
To understand the use of Iterate Feature Classes in ModelBuilder, see the illustration below, where the model finds the population density for the Block and Parcel feature classes in the Input Feature Classes variable.
The iteration has been restricted by choosing the POLYGON feature type; therefore, the iterator only iterates on the Block and Parcel polygon feature classes.
The tool has two outputs:
- Output Feature Class variable (Block and Parcel) connected to the Add Field tool as input.
- Name variable (Block and Parcel, in this example), which could be used as the in-line variable %Name% in other tools.
Iterate Files
To understand the use of Iterate Files in ModelBuilder, see the illustration below, where the Input Folder variable has a list of ASCII files to be converted to raster. The iteration has been restricted with a wildcard f* and the file extension .txt so that it will only iterate over files starting with letter F and of type text.
The tool has two outputs:
- The File variable (focaldem1.txt, focaldem2.txt, or focaldem3.txt) connected as input to the ASCII To Raster tool.
- Name variable containing the name of the text file (focaldem1, focaldem2, or focaldem3). This Name variable is used in output of the next tool as an in-line variable %Name%.
Iterate Rasters
To understand the use of Iterate Rasters in ModelBuilder, see the illustration below, where the model resamples grid datasets and extracts a subset for further analysis.
The Input Rasters variable is a folder containing grids, images, and TIFFs. In this case, iteration has been restricted with a wildcard A* and raster type of GRID so that it only iterates over rasters starting with the letter A and only on grids.
The tool has two outputs:
- Output Raster variable (Aland, Aparcel, and Aroad) connected as input to the Resample tool.
- Name variable, which is used in the output name of the Resample and Extract Subset tools as the in-line variable %Name%.
Iterate Tables
To understand the use of Iterate Tables in ModelBuilder, see the illustration below, where the model transposes land-cover tables of each state with a land-cover type and summarizes the statistics—like sum of area—for each class of land cover.
The input workspace variable is a folder containing the tables. The iteration has been restricted with a wildcard L* and a table type of DBASE so that it only iterates over dBASE tables starting with the letter L.
The tool has two outputs:
- Output Table variable (Landcover_Arizona, Landcover_California, and Landcover_Nevada) connected to the Pivot Table tool as input.
- Name variable, which is used as an in-line variable %Name% in the output names of the Pivot Table and Summary Statistics tools.
Iterate Workspaces
To understand the use of Iterate Workspaces in ModelBuilder, see the illustration below, where the model creates a new mosaic using rasters stored in a geodatabase named Arizona, which is stored inside a folder.
The iteration has been restricted with the wildcard Ar* and workspace type of FILEGDB so that it only iterates over file geodatabases with names starting with the letters Ar.
The tool has two outputs:
- Output Workspace variable (Arizona GDB) connected to the Workspace To Raster Dataset tool as input.
- Name variable, which can be used as an in-line variable %Name% in the output name of subsequent tools.