Work with Iterate Feature Selection

Summary

The Iterate Feature Selection tool iterates over features in a feature class.

Finished model to iterate over feature selection

In this workflow, you'll create a model to iterate over features grouped by regions in a feature class (USA states) and create eight feature classes, one for each group or region. The field value (region) used to split the feature class is also used as the name of the output feature class. The region names includes spaces. For example, Pacific West Region, Mid Atlantic Region, and so on. Space is not accepted as a valid file name character in a file geodatabase. To remove unacceptable spaces, the iterator’s output parameter Value (region name) is altered by using it as an inline variable in the Calculate Value tool (%Value%). The output of the Calculate Value tool is finally used as an inline variable in the output name of the Copy Features tool (%Name%). The output of the Copy Features tool is connected to the Collect Values tool, which collects the output of each iteration and outputs a single multivalue output.

Prerequisites

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

Open the project

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

  1. Open the Work with Iterate Feature Selection overview page.
  2. Click Download on the right side of the page.
  3. Right-click the downloaded IterateFeatureSelection.zip file and extract it to a convenient location, such as C:\Temp
  4. In the extracted folder, IterateFeatureSelection, double-click the ArcGIS Pro project file, IterateFeatureSelection.aprx.
  5. Explore the data in the Catalog pane, and click the Project tab if necessary. Browse to Folders > IterateFeatureSelection.

    The ToolData.gdb geodatabase contains the States feature class, which will be used as the input for the model.

    The outputs of the model will be written to the ScratchStates.gdb geodatabase.

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

    Adding the Iterate Feature Selection tool

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

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

    Adding the Calculate Value tool

    The Calculate Value tool is added to the model.

  5. Add the Collect Values tool in the model, as described in the previous step.
  6. Add the Copy Features tool.
    1. Click in the model, and type Copy Features to open the Add Tools To Model dialog box.
    2. Search for the Copy Features tool.
    3. Double-click the Copy Features tool and add it to the model.

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 Iterate Feature Selection iterator to open the iterator's dialog box.
    1. For the In Features parameter, browse to <Your Project Location>\IterateFeatureSelection\ToolData.gdb and select the States feature class.
    2. Leave the rest of the parameters empty and click OK.

    Iterate Feature Selection tool dialog box

    The Input Feature Class is added as a model variable in the model (dark blue oval) 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 Feature Selection iterator and click Create Variable > From Parameter > Group By Fields to expose the Group By Field parameter as a variable in the model.
    1. Double-click the Group By Field model variable and from the drop-down list, select Region.
    2. Click OK to close the dialog box.

    Iterate Feature Selection tool Group by Field setting

    The Region field value will be used to select features for each iteration.

  3. Double-click the Calculate Value tool to open the tool's dialog box. For the Expression parameter, type "%Value%".replace(" ","") and change Data type to String.

    The expression has the following parts:

    Calculate Value tool dialog box

    At run time, %Value%, which is the region name of the iterator output parameter (light blue oval), is replaced by the value of the variable, for example, Pacific West Region, Mid Atlantic Region and so on.

  4. Click OK to close the dialog box.
  5. In ModelBuilder, tools honor the hierarchy and run only if the connected upstream tool runs first. The Calculate Value tool uses the output Value parameter of the iterator in its expression, but is not connected to it and will fail if it does not find the region name. You want the iterator to run before the Calculate Value tool so that the region name is available. For this, you'll set the Value variable as a precondition on the Calculate Value tool.

    Hover over the Iterate Feature Selection tool output variable Value (light blue oval). Click and drag to draw a connector line to the Calculate Value tool. Release the mouse and click Precondition on the pop-up menu.

    Setting the Calculate Value tool precondition

  6. Right-click the States variable (dark blue oval) and click Rename. Type Input Feature Class for a new name. In a similar way rename the output of the iterator I_States (green oval) to Selected Features and the output of the Calculate Value tool to Name.
  7. Hover over the Calculate Value tool output variable Name (green oval). Click and drag to draw a connector line to the Copy Features tool. Release the mouse and click Precondition on the pop-up menu.
  8. Double-click the Copy Features tool to open the tool's dialog box.
    1. For the Input Features, choose the Selected Features from the drop-down list.
    2. For the Output Feature Class parameter, browse to <Your Project Location>\ScratchStates.gdb and type %Name%.

    Copy Features tool dialog box

    Leave the rest of the parameter default setting and click OK to close the Copy Features tool dialog box.

  9. Hover over the Copy Features tool output variable (green oval). 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.
  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

  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 of the Iterate Feature Selection model

    The model iterates over eight groups of features and creates eight feature classes in the ScratchStates.gdb geodatabase.

  4. Close the model and ArcGIS Pro.