Work with For iterator

Summary

The For tool iterates over a starting and ending value by a given value. It works like For in any scripting or programming language, executing through a set number of items.

Finished model using For iterator

In this workflow, you'll create a simple model that identifies the impact of proposed roads based on vegetation type and proximity to the road. In the model, the roads are first buffered three times with distance values of 500 feet, 1000 feet, and 1500 feet. These distance values are derived from the For iterator. The buffer zones are then used to clip the vegetation data using the Clip tool to create a dataset of vegetation types within the buffer polygons. The Summary Statistic tool then summarizes the affected area by vegetation type within the buffer polygons around the proposed roads. The Collect Values tool collects all the outputs of the iterations and adds them to the Contents pane for display in ArcGIS Pro.

Prerequisites

If you are new to ModelBuilder, review the following topics:

Open the project

Download the project to use in this workflow. The project includes an input geodatabase, an output geodatabase and a completed model.

  1. Open the Work with For iterator overview page.
  2. Click Download on the right side of the page.
  3. Right-click the downloaded IterateFor.zip file and extract it to a convenient location, such as C:\Temp.
  4. In the extracted folder, IterateFor, double-click the ArcGIS Pro project file, IterateFor.aprx.

    The project opens to an empty map and will be used to view the results from the model you will create in this workflow.

  5. Explore the data in the Catalog pane, and click the Project tab if necessary. Browse to Folders > IteratorFor.
  6. The Data.gdb geodatabase has PlanA_Roads and vegtype feature classes, which will be used as model inputs. The ScratchCommon.gdb geodatabase will be used to save model outputs.

Add tools

You'll create a model in the MyProjectTools toolbox. To add tools to the model, complete the following steps:

  1. In the Catalog pane, click the Project tab if necessary. Browse to Folders > IterateFor > MyProjectTools.
  2. Right-click MyProjectTools and click New. Select Model to create and open a model.
  3. Add the For tool.
    1. On the ribbon, click the ModelBuilder tab.
    2. In the Insert group, click Iterators Iterators.
    3. In the Iterators list, click For

    Adding the For iterator

    The For iterator is added to the model. The iterator is unavailable since no parameter values have been provided.

  4. Add the Collect Values tool.
    1. On the ribbon, click the ModelBuilder tab.
    2. In the Insert group, click Utilities Utilities.
    3. In the Utilities list, click Collect Values.

    Adding the Collect Values tool

    The Collect Values tool is added to the model.

  5. Add the Buffer tool.
    1. Click in the model, and type Buffer to open the Add Tools To Model dialog box.
    2. Search for the Buffer tool.
    3. Double-click the Buffer tool and add it to the model.
  6. Add the Clip and Summary Statistics tools to the model, as described in the previous step.

Specify the tool parameters and connect the tools

After adding tools to the model, you need to specify the parameters for each tool.

  1. Double-click the For iterator to open the iterator's dialog box. .
    1. For From Value, To Value, and By Value, type 500, 1500, and 500, respectively.
    2. Click OK to close the dialog box.

    For iterator dialog box

    When the tool runs, the model will output 500 for the first iteration, and then 1000 and 1500.

  2. Double-click the Buffer tool to open the tool's dialog box.
    1. For the Input Features parameter, click the browse button Browse and browse to the <Your Project Location>\IterateFor\Data.gdb geodatabase. Select the PlanA_Roads feature layer.
    2. For the Output Feature Class parameter, browse to the <Your Project Location>\IterateFor\ScratchCommon.gdb geodatabase and type BufferedFC_%Value%.

      At run time, %Value%, which is the name of the output variable of the For iterator (light blue oval), will be replaced by the value of the variable 500, 1000, or 1500.

      Tip:

      In ModelBuilder, the value or dataset path of a variable can be substituted for another variable by enclosing the substituting variable name in percent signs (%VariableName%). Substituting variables in this manner is called inline variable substitution

    3. For the Distance [value or field] parameter, choose the Linear Unit option; leave the distance blank and set the units to Feet.
    4. Leave the remaining parameter default settings and click OK to close the dialog box.

    Buffer tool dialog box

  3. Hover over the For iterator output variable Value. Click and drag to draw a connector line to the Buffer tool. Release the mouse and click Distance [value or field] on the pop-up menu.
  4. Double-click the Clip tool to open the tool's dialog box.
    1. For the Input Features parameter, click the browse button Browse and browse to the <Your Project Location>\IterateFor\Data.gdb geodatabase. Select the vegtype feature layer.
    2. For the Clip Features parameter, click the drop-down arrow and select BufferedFC_%Value%.
    3. For the Output Feature Class parameter, browse to the <Your Project Location>\IterateFor\ScratchCommon.gdb geodatabase and type ClippedFC_%Value%.

      At run time, %Value%, which is the name of the output variable of the For iterator (light blue oval), will be replaced by the value of the variable 500, 1000, or 1500.

    4. Leave the remaining parameter default settings and click OK to close the dialog box.

    Clip tool dialog box

    A connection is created between the output value of the Buffer tool and the Clip tool.

  5. Double-click the Summary Statistics tool to open the tool's dialog box.
    1. For the Input Table parameter, click the drop-down arrow and select ClippedFC_%Value%.
    2. For the Output Table parameter, browse to the <Your Project Location>\IterateFor\ScratchCommon.gdb geodatabase and type AffectedVegetation%Value%.

      At run time, %Value%, which is the name of the output variable of the For iterator (light blue oval), will be replaced by the value of the variable 500, 1000, or 1500.

    3. For the Statistics Field(s) parameter, select Shape_area for the Field column, and Sum for the Statistic Type column.
    4. For the Case field parameter, select VEG_TYPE.
    5. Click OK to close the dialog box.
    Summary Statistics tool dialog box
  6. Hover over the Clip tool output variable. Click and drag to draw a connector line to the Collect Values tool. Release the mouse and click Input Value on the pop-up menu. Follow the same procedure to connect the Summary Statistics tool output variable and the Collect Values tool.

    It is good practice to rename the input and output variable names to be more meaningful instead of using the default variable name.

  7. Right-click the output of the Buffer tool and click Rename. Type Buffered FC for a new name. Similarly rename all the variables, as shown in finished model.
  8. To arrange the model elements, click the Auto Layout button Auto Layout on the ModelBuilder tab and click the Fit To Window button Fit To Window to maximize the layout to the size of your model window.

Run the model

  1. Right-click the output of the Collect Values tool, and click Add To Display.

    The output is added to the map.

  2. Click the Save button Save on the ModelBuilder tab to save the model.
  3. Click the Run button Run on the ModelBuilder tab to run the model.
    Output from the For iterator model

    The model iterates over all the distance values from the For iterator, buffers the input feature class for all the distance values, clips the feature classes, and summarizes the affected area by vegetation type.

  4. In the Contents pane, right-click the added tables and select Open Open Table to see which vegetation types would be most impacted by the proposed roads for each of the buffered distances.
  5. Close the model and ArcGIS Pro.