Create a model within a model, or a nested model. The model iterates over a few feature classes, projects them, and merges them to create a single feature class.
A nested model is required when part of a model does not need to run multiple times. If an iterator is added to a model, all tools in that model are run for each value the iterator returns. In this example, you'll iterate the Project tool for each feature class; however, running the Merge tool multiple times does not make sense, as it takes all the projected feature classes together and creates a merged output by running only once. Therefore, the Merge tool is added to a main model that runs once and calls a submodel that runs more than once.
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, an output geodatabase, and a completed model.
- Open the Work with Model Within A Model overview page.
- Click Download on the right side of the page.
- Right-click the downloaded ModelWithinModel.zip file and extract it to a convenient location, such as C:\Temp.
- In the extracted folder, ModelWithinModel, double-click the ArcGIS Pro project file, ModelWithinModel.aprx.
- Explore the data in the Catalog pane, and click the Project tab if necessary. Browse to Folders > ModelWithinModel.
The ToolData.gdb geodatabase contains three feature classes that will be used as inputs for the model.
The outputs of the model will be written to the ScratchCommon.gdb geodatabase.
You'll create a model in the MyProjectTools toolbox. To add tools to the model, complete the following steps:
- In the Catalog pane, click the Project tab. Browse to Folders > ModelWithinModel > MyProjectTools.
- Right-click MyProjectTools and click New. Select Model to create and open a model.
- On the ribbon, click the ModelBuilder tab. In the Model group, click Properties . On the Tool Properties dialog box, type ProjectMainModel for Name and Project Main-Model for Label.
- On the ribbon, under the ModelBuilder tab, in the Model group, click the Save button to save your changes.
- Create another model with the Name of ProjectSubModel and the Label of Project Sub-Model.
- In the Project Sub-Model model, add the Iterate Feature Classes tool.
- On the ribbon, click the ModelBuilder tab.
- In the Insert group, click Iterators .
- In the Iterators list, click Iterate Feature Classes.
The Iterate Feature Classes tool is added to the Project Sub-Model model. The iterator is unavailable since no parameter values have been provided.
- Add the Collect Values tool.
- On the ribbon, click the ModelBuilder tab.
- In the Insert group, click Utilities .
- In the Utilities list, click the Collect Values tool.
The Collect Values tool is added to the Project Sub-Model model.
- Add the Project tool.
- Click in the model, and type Project directly in the model to open the Add Tools To Model dialog box.
- Search for the Project tool.
- Double-click the Project 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.
- Double-click the Iterate Feature Classes tool to open the iterator's dialog box.
- For the Workspace or Feature Dataset parameter, browse to the ToolData.gdb geodatabase.
- Keep the default values for the remaining parameters, and click OK.
The workspace is added as a model variable to the model (dark blue oval) and the color of the iterator changes, indicating that the required parameters have been supplied and it is ready to run.
- Right-click the output of the iterator and click Rename. Type Feature Class for the name.
- Double-click the Project tool to open the tool's dialog box.
- For the Input Dataset or Feature Class parameter, choose Feature Class from the drop-down list.
- For the Output Dataset or Feature Class parameter, browse to <Your Project Location>\ScratchCommon.gdb and type %Name%_Projected.
- For the Output Coordinate System parameter, select Projected Coordinate System > State Plane > NAD 1983 (Meters) > NAD 1983 StatePlane Oregon North FIPS 3601 (Meters).
- Keep the default values for the remaining parameters, and click OK to close the Project tool dialog box.
If your input feature classes have different coordinate systems, the geographic transformation may not apply to all and might project the data incorrectly. Be aware of your input coordinate systems and which geographic transformation methods applies to them. Use the iterator's Wildcard parameter to selectively project feature classes in such cases.
- Hover over the Project 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.
The Collect Values tool is a model utility tool used to collect the output values of each iteration into a single multivalue output.
- Right-click the input variable to the iterator and check Parameter.
This adds a letter P next to the variable, indicating that it is a model parameter.
- Create a model parameter from the output of the Collect Values tool in the same way you did above.
- To arrange the model elements, click the Auto Layout button on the ModelBuilder tab and click the Fit To Window button to maximize the layout to the size of your model window.
- Click the Save button on the ModelBuilder tab to save the model, and close the Project Sub-Model model.
- In the Project Main-Model model, search for the Merge tool and add it to the model.
- In the Catalog pane, browse to the Project Sub-Model model you just created. Drag the Project Sub-Model model into the Project Main-Model model.
The submodel is added to the main model. The submodel parameters are added as variables to the main model (the dark blue oval for ToolData.gdb and the green oval for Output Values).
- Hover over the Project Sub-Model output variable Output Values (green oval). Click and drag to draw a connector line to the Merge tool. Release the mouse and click Input Datasets on the pop-up menu.
This creates a connection between the submodel output and the Merge tool.
- Double-click the Merge tool to open the tool's dialog box. For the Output Dataset parameter, browse to <Your Project Location>\ScratchCommon.gdb geodatabase and type ProjectedFC_Merge. Leave the default value for the Field Map parameter and click OK to close the dialog box.
It is good practice to rename the input and output variable names to more meaningful names instead of using the default variable names.
- Rename the Merge tool output Merged Feature Class. Rename all the other model variables as shown in the finished model of the workflow.
Run the model
You'll validate and run the model. You'll examine the outputs in the ScratchCommon.gdb geodatabase and confirm that all feature classes have been merged after projection.
- Right-click the output of the Merge tool, and click Add To Display.
The outputs are added to the map.
- Click the Save button on the ModelBuilder tab to save the model.
- Click the Run button on the Project Main-Model tab to run the model.
The model runs the submodel and iterates over all the feature classes, projects them, and creates the output in the ScratchCommon.gdb geodatabase. The Collect Values tool collects the outputs in the submodel and passes the datasets to the Input Datasets parameter of the Merge tool. The Merge tool runs once and creates a merged output.
- Close the model and ArcGIS Pro.