Skip To Content

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 inline variable substitution.

Use of For in ModelBuilder

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 inline variable in the output name of the Output Table variable.

How to use Iterate Feature Selection

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 inline variable in the output name of the Output Standard Deviational Ellipse variable.

How to use Iterate Row Selection

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 variable containing 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 inline variable substitution.

How to use Iterate Field Values

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.

How to use Iterate Multivalue

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 (Land and Transportation).
  • Name, which is used as the inline variable %Name% in the output of the Copy tool.

How to use Iterate Datasets

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 Blocks and Parcels 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 Blocks and Parcels polygon feature classes.

The tool has two outputs:

  • Output Feature Class variable (Blocks and Parcels) connected to the Add Field tool as input.
  • Name variable (Blocks and Parcels, in this example), which could be used as the inline variable %Name% in other tools.

How to use Iterate Feature Classes

Iterate Files

To understand the use of Iterate Files in ModelBuilder, see the illustration below, where the Input Folder variable has a list of text 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 or 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.
  • The 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 inline variable %Name%.

How to use Iterate Files

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 or 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 inline variable %Name%.

How to use Iterate Rasters

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—such as 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 or 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 inline variable %Name% in the output names of the Pivot Table and Summary Statistics tools.

How to use Iterate Tables

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 file geodatabase so that it only iterates over file geodatabases with names starting with the letters Ar.

The tool has two outputs:

  • Output Workspace variable, containing Arizona.gdb, is connected to the Workspace To Raster Dataset tool as input.
  • Name variable, which can be used as an inline variable %Name% in the output name of subsequent tools.

How to use Iterate Workspace