Work with Iterate Feature Classes

Summary

The Iterate Feature Classes tool iterates over feature classes in a workspace or feature dataset. Each iterator has a set of parameters that may differ from the other iterators, but the overall structure of all iterator tools is very similar. The Iterate Feature Classes tool is described below:

Iterate Feature Classes parameters

  • Input Feature Classes (input)—A workspace or feature dataset that stores the feature classes to iterate.
  • Wildcard (optional input)—A combination of asterisks and characters used to limit the results. An asterisk is the same as requested all. If no wildcard is specified, all inputs will be returned.
  • Feature Type (optional input)—The feature type to be used as a filter. Only features of the specified type will be output. Not specifying a feature type means that all feature types will be returned.
  • Recursive (optional input)—Specifies whether the iterator will iterate through all subfolders in the main workspace.
  • Feature Class (output)—The full path to the feature class.
  • Name (output)—The name of the feature class.

In this workflow, you'll create a model (shown below) to iterate and project each feature class in the input model workspace and use the output Name parameter as the inline variable in the output Feature Class name of the Project tool. The workflow will take you step-by-step through each parameter option of the iterator to highlight its functionality.

Finished model to iterate and project 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, output geodatabases, and a completed model.

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

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

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

    The Data folder includes subfolders; each subfolder includes feature classes that will be iterated over and projected in the model. The outputs of this workflow will be saved in the three Scratch* geodatabases.

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

    Adding the Iterate Feature Classes tool

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

  4. Add the Project tool.
    1. Click in the model, and type Project to open the Add Tools To Model dialog box.
    2. Search for the Project tool.
    3. Double-click the Project tool to add it to the model.
  5. Add the Collect Value tool.
    1. Click the ModelBuilder tab.
    2. In the Insert group, click the Utilities button Utilities.
    3. In the Utilities list, click Collect Values to add the Collect Values tool to the model.

    Adding the Collect Values tool

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 Classes iterator to open the iterator's dialog box.
    1. For the Workspace or Feature Dataset parameter, browse to the Folders > IterateFeatureClasses > Data folder.
    2. Check the Recursive check box to iterate over all the feature classes in all subfolders.
    3. Leave the rest of the parameters empty and click OK.

    Iterate Feature Classes dialog box

    The workspace as an input variable of the model (dark blue oval) is added and changes the color of the iterator, indicating that the required parameters have been supplied and it is ready to run.

  2. Double-click the Project tool to open the tool's dialog box.
    1. Click the Input Dataset or Feature Class parameter drop-down arrow and select Metro_Entrances.shp.
    2. For the Output Dataset or Feature Class parameter, browse to the <Your Project Location>\IterateFeatureClasses\ScratchAllFC.gdb geodatabase and type %Name%_Project.
    3. Click the Coordinate System button Coordinate System on the Output Coordinate System parameter to open the Coordinate System dialog box. Select Projected Coordinate System > Continental > Europe > Europe Albers Equal Area Conic. Click OK to close the dialog box.
    4. Keep NTF_TO_ED_1950 for the Geographic Transformation method.
    5. Click OK to close the Project tool dialog box once all the parameters are filled in.

    Project tool dialog box

    Caution:

    If your input feature classes have different coordinate systems, the added geographic transformation may not apply to all and might project the data incorrectly. You should be aware of what the coordinate systems of your inputs are and which geographic transformation method applies to them. Use the iterator's Wildcard parameter to selectively project feature classes in such cases. You will learn more about using the wildcard in the Use the Wildcard optional parameter section.

  3. Hover over the Project tool output variable. Click and drag to draw a connector line to the Collect Values tool element. Release the mouse and click Input Value on the pop-up menu. The Collect Values tool is a supporting tool used to collect the output values of each iteration into a single multivalue output.
  4. Rename all the model variables as shown in the finished model in this workflow.
  5. 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 ScratchAllFC.gdb and confirm that all feature classes within the Data folder have been iterated and projected.

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

    The outputs are added to the map after running the model.

  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 Iterate Feature Classes model

    The model iterates over all feature classes within the Data folder, projects them, and creates the output in the ScratchAllFC.gdb geodatabase.

Use the Wildcard optional parameter

These steps extend the workflow to learn about the use of the Wildcard optional parameter of the iterator.

  1. After you have finished the sections above and created the output projected feature classes, double-click and open the Iterate Feature Classes tool.
  2. Type Metro* in the Wildcard parameter. Leave the Recursive parameter checked. This ensures that the model iterates over all the subfolders but will only project the feature classes with a name beginning with Metro. At run time, * will be replaced with the remainder of the feature class name starting with Metro.
  3. Click OK to close the tool dialog box.
  4. Open the Project tool dialog box and change the Output Dataset or Feature Class option to <Your Project Location>\IterateFeatureClasses\ScratchWildCard.gdb\%Name%_Project.
  5. Click OK to close the dialog box.
  6. Click the Save button Save on the ModelBuilder tab to save the model.
  7. Click the Run button Run on the ModelBuilder tab to run the model.
    Output from Iterate Feature Classes model using Wildcard

    The model iterates over all the feature classes with a name starting with Metro, projects them, and creates the output in the ScratchWildCard.gdb geodatabase.

Use the Wildcard and Feature Type optional parameters

These steps extend the workflow further to learn about the use of the Feature Type optional parameter of the iterator.

  1. After you have finished the Using Wildcard optional parameter section and created the output projected feature classes, double-click and open the Iterate Feature Classes tool.
  2. Click the Feature Type parameter drop-down arrow and select the Line option. This ensures that the model iterates over all Line feature classes with a name starting with Metro.
  3. Click OK to close the tool dialog box.
  4. Open the Project tool dialog box and change the Output Dataset or Feature Class option to <Your Project Location>\IterateFeatureClasses\ScratchOnlyLine.gdb\%Name%_Project.
  5. Click the Save button Save on the ModelBuilder tab to save the model.
  6. Click the Run button Run on the ModelBuilder tab to run the model.
    Output from Iterate Feature Classes model using WildCard and Feature Type

    The model iterates over all the line feature classes with a name starting with Metro, projects them, and creates the output in the ScratchOnlyLine.gdb geodatabase.

  7. Close the model and ArcGIS Pro.