Work with Iterate Multivalue

Summary

The Iterate Multivalue tool iterates over a list of values.

Finished model to iterate over multivalue

In this workflow, the Iterate Multivalue iterator is used to iterate over airports, freeway exits, and recreational areas feature classes. The other input is a point feature class, and the model calculates the closest distance of each point in the feature class to the airports, freeway exits, and recreational areas using the Near tool. The Near tool adds a field with the distance value for each input point to the nearest feature in a feature class, and the field values are overwritten for each iteration. To avoid losing the distance value after each iteration, the model adds a field and copies the distance values using the Calculate Field tool. The Parse Path tool is used to extract the name of the near feature class (airport, exits, and recareas). These names are then used as field names in the Add Field tool.

Workflow illustration

This illustration shows a subset the map of the input point feature class and all the feature classes for which the near distance will be calculated. The attribute table of the input point feature class shows the field added and values calculated for each of the input near feature classes.

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 input data and a completed model.

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

  5. Explore the data in the Catalog pane, and click the Project tab if necessary. Browse to Folders > IterateMultivalue.

    The ToolData.gdb geodatabase contains the data that will be used as model inputs. The model updates the PointLocation feature class attribute table.

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 > IterateMultivalue > MyProjectTools.
  2. Right-click MyProjectTools and click New. Select Model to create and open a model.
  3. Add the Iterate Multivalue tool.
    1. Click the ModelBuilder tab.
    2. In the Insert group, click Iterators Iterators.
    3. In the Iterators list, click Iterate Multivalue.

    Adding the Iterate Multivalue tool

    This adds the Iterate Multivalue iterator to the model. The iterator is unavailable since no parameter values have been provided.

  4. Add the Parse Path tool.
    1. Click the ModelBuilder tab.
    2. In the Insert group, click Utilities Utilities.
    3. In the Utilities list, click the Parse Path tool.

    Adding the Parse Path tool

    This adds the Parse Path tool to the model.

  5. Add the Near tool.
    1. Click in the model, and type Near in the model to open the Add Tools To Model dialog box.
    2. Search for the Near tool.
    3. Double-click the Near tool and add it to the model.
  6. In the same way as the previous step, add the Add Field and Calculate Field tools to the model.

Specify the tool parameters and connect the tools

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

  1. Double-click the Iterate Multivalue iterator to open the iterator's dialog box. For the Input Values parameter, browse to <Your Project Location>\IterateMultivalue\ToolData.gdb and select the airports, exits, and recareas feature classes and click OK.

    Iterate Multivalue tool dialog box

    This adds the input feature classes as model variables in the model (dark blue ovals) and changes the color of the iterator, indicating that the required parameters have been supplied and it is ready to run.

  2. Right-click the output of the iterator and click Rename. Type Value for the name and press Enter. This renames the output variable of the iterator.
  3. Double-click the Near tool to open the tool's dialog box.
    1. For the Input Features parameter, browse to <Your Project Location>\IterateMultivalue\ToolData.gdb and select the PointLocation feature class.
    2. For the Near Features parameter, choose the Value from the drop-down list.

    Near tool dialog box

    Leave the rest of the parameters as default and click OK. This creates a connection between the output value of the iterator and the Near tool.

  4. Double-click the Parse Path tool to open its dialog box and select Value from the drop-down list for the Input Values parameter.

    Parse Path tool dialog box

    This creates a connection between the output of the iterator and the Parse Path tool.

  5. Hover over the Near tool output variable (green oval). Click and drag to draw a connector line to the Add Field tool. Release the mouse and click Input Table on the pop-up menu.
  6. Double-click the Add Field tool to open the tool's dialog box.
    1. The Input Table parameter is already added from the output of the Near tool.
    2. For the Field Name parameter, type %Name% as an inline variable substitution.

      At run time, the name of the feature class, either airports, exits, or recareas, will be used as a field name.

    3. For the Field Type parameter, select Double (double precision) from the drop-down list.

    Leave the rest of the parameters as default and click OK.

    Add Field tool dialog box

  7. In ModelBuilder, a tool honors the hierarchy and runs only if the upstream tool to which it is connected runs first. The Add Field tool uses the output Name parameter value of the Parse Path tool in its Field Name parameter but is not connected to it and would fail if it does not find the field name. To run the Parse Path tool before the Add Field tool, such that the name is available, a precondition must be set on the Add Field tool.

    Hover over the Parse Path tool output variable Name. Click and drag to draw a connector line to the Add Field tool. Release the mouse and click Precondition on the pop-up menu.

    Setting the Precondition parameter for the Add Field tool

  8. Hover over the Add Field tool output variable (green oval). Click and drag to draw a connector line to the Calculate Field tool. Release the mouse and click Input Table on the pop-up menu.
  9. Double-click the Calculate Field tool to open the tool's dialog box.
    1. The Input Table parameter is already added from the output of the Add Field tool.
    2. For the Field Name parameter, select %Name% from the drop-down list. This is the field added by the Add Field tool. At run time, the variable name between the percent signs will be replaced by the actual name of the field.
    3. For the Expression Type parameter, select Python 3.
    4. For the Expression parameter, type !NEAR_DIST!.

      Values of the NEAR_DIST field will be copied to the new field. You cannot select NEAR_DIST from the list of Fields because the field does not exist since the Near tool has not run yet. Typing the field name like this requires prior knowledge of the tool and the output field that the tool is going to create. The exclamation points before and after the field name are field delimiters for Python expressions.

    Calculate Field tool dialog box

  10. Rename all the model variables as shown in the finished model.
  11. 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

You'll validate and run the model. You'll examine the outputs in the input point feature class attribute table and confirm that the nearest distance values from all three feature classes are added.

  1. Right-click the output of the Calculate Field tool, and click Add To Display.

    The updated input feature class 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. The model will iterate over all three features classes and find the closest distance for each feature class to the point features. Right-click the input feature class in the ArcGIS Pro Contents pane and click Tables to see the added fields with nearest distance values.
  4. Close the model and ArcGIS Pro.