ModelBuilder 360: Amp Up the Automation

This is the third post in a three-part series on creating geoprocessing models in ArcGIS.

If you’ve read the previous posts in this series, you’ve got modeling basics down and you know how to add model parameters to support easy reuse and scenario testing. In this post, you’ll learn some techniques to do more with less—effort, that is. 

List Variables

In the last post, you learned how to make a tool parameter a variable, and turn a variable into a model parameter. By default, a variable stores a single value. However, it’s possible to store multiple values in a variable. When you do, the variable is called a list variable.

When a list variable is connected to a geoprocessing tool, that tool and all downstream processes (all the processes that depend on the tool’s output) will automatically execute once for each value in the list. That’s right: when you define a list variable, model tools automatically know to process each list item.

Using list variables is like running geoprocessing tools in batch mode—with the major advantage that you have to enter the list of values only once to achieve multi-tool processing.

Consider the model below, which automates a typical data management workflow.

ArcGIS geoprocessing model

This model creates a file geodatabase, converts a shapefile to a geodatabase feature class, removes duplicate features, defines the coordinate system for the feature class, and outputs a layer with selected features. Notice the model even has two parameters. It’s a complete workflow that works great when a single shapefile needs to be processed.

It falls short, though, when multiple shapefiles need to be processed. The model would have to be run manually multiple times to process all the shapefiles. Wouldn’t it be better to run the model once and have all the work done?

Creating a list variable will accomplish this. To create a list variable for this example:

Specifying inputs to a list variable

  1. Right-click the Feature Class to Feature Class tool input variable and click Properties, then click “A list of values.” Click OK.
  2. Double-click the variable to open it and enter each value.

Inline variable substitution

With list variables, tools run multiple times to process each input. By default, however, the tool output names will be the same—which means all but the last list item’s outputs will be overwritten. To overcome this, use inline variable substitution.

There are two types of variables that can be substituted in processes: model variables and system variables. To use a model variable for inline variable substitution, just enter the variable name surrounded by percent signs.

The system variable %i% is often used to add a unique, sequential number to the end of output names. List item numbering starts at 0 (the first item’s output name will have a 0 appended).

For this example, you would open the Feature Class to Feature Class tool and add a lowercase i surrounded by percent signs to the end of the output feature class name (ASAM in this case).

Feature Class to Feature Class tool outputs using a system variable

Using the system variable ensures the model will correctly process and create the three outputs needed. However, the output names are not descriptive. You could rename them later, but why not automate that work now?

Model-Only Tools

ModelBuilder includes a set of tools that are available only for models that will be run inside ModelBuilder (i.e., they won’t work when the model is run as a tool). The Parse Path tool allows you to separate an input path into its component parts, then reference those parts in downstream processes.

In this example, the Parse Path tool is a better alternative to using a system variable for the model processes. It allows the input shapefile names to be used in the output names instead of cryptic numbers.

  • Note: For processes that create intermediate data, using a system variable is a good solution when output names must have unique names but you don’t need to worry about those names causing confusion.

To add the Parse Path tool: ModelBuilder Parse Path tool dialog box

  1. Click the Insert menu > Model Only Tools > Parse Path.
  2. From the model window, open the Parse Path tool. For Input Data Element, choose Input Shapefile.
  3. For Parse Type, choose Name, then click OK.
  4. Connect the Parse Path output (Value) to the Feature Class to Feature Class tool as the Output Feature Class.

Using Parse Path, tool outputs are descriptively named

When you hover over the Feature Class to Feature Class output element, you can see that the three outputs now have names corresponding to the input shapefile names. This will make the model outputs immediately understandable to the people who need to work with the data.

Preconditions

Did you notice that the Input Shapefile element now links to two tools—Parse Path and Feature Class to Feature Class—and that Parse Path isn’t part of the main model workflow? When a model contains separate but related processes, the order in which those processes execute is unpredictable. You can control processing order by setting a precondition.

In the example, the potential exists for the Feature Class to Feature Class process to run before the Parse Path process…which means the model outputs will be overwritten as each list item is processed.

Setting a precondition for the Feature Class to Feature Class tool

To ensure the Parse Path tool always runs before Feature Class to Feature Class, make the Value element a precondition to the Feature Class to Feature Class tool.

To set a precondition:

  1. Right-click the Feature Class to Feature Class tool and click Properties.
  2. In the dialog box, click the Preconditions tab and check Value. Click OK.

Any model element can be set as a precondition to a model tool, and tools can have more than one precondition.

Go Ahead, Model It

By visually mapping workflows, automating time-consuming tasks, and supporting rapid “what if” scenario testing, models are a valuable tool to help GIS professionals work more efficiently and collaboratively. With a solid understanding of modeling basics and a few advanced techniques in your back pocket, you may find yourself jumping at opportunities to build models in ArcGIS. Because besides being geoprocessing workhorses, models are…fun.


Related posts:

For hands-on practice with ModelBuilder, this e-learning course is recommended.

SuzanneB

About SuzanneB

Suzanne is a Maryland native with a degree in English Literature who enjoys writing about Esri technology and other topics. She works with Esri Training Services in Redlands, California.
This entry was posted in ArcGIS Step by Step, export and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

7 Comments

  1. Pingback: ModelBuilder 360: Amp Up the Automation | GIS Tidings

  2. Pingback: ModelBuilder 101 | Esri Training Matters

  3. Pingback: ModelBuilder 220: Add Flexibility | Esri Training Matters

  4. yppmark says:

    These are great. Thanks Suzanne. What would be really great would be a tutorial on the various iterators in ModelBuilder especially how to process a series of files in a directory.

  5. jmmlourenco_ says:

    Hello!
    Sorry if this is not the proper place to put my doubt.
    A model I made iterates all the feature classes of a feature dataset. In that model I also need to run a tool (only) after all the feature classes have been iterated. The way I found to make that check uses an input parameter relative to the number of feature classes in the feature dataset, but the ideal should be determine automatically that number. Is there a way to determine automatically the number of feature classes in a feature dataset?
    Thanks