Modelbuilder is often an afterthought to most GIS analysts, however, it can be a powerful tool when it comes to building and replicating complex workflows, as well as automating those boring, tedious tasks.
Iterators are unique to models, and allow you to loop through a process on unique values, tables, layers in your map document, or even workspaces.
Let’s have a look at iterators, and how you can use them.
Iterators can be enabled through the context menu within the model itself. You have a few options available, as can be seen in the image below. For the moment, you can only use one iterator per model (more on this later).
You can read about the individual capabilities of each here:
The best way to understand this is to look at a simple scenario. Perhaps I have a dataset that I want to filter based on a unique value. For each unique value that I specify (in an excel table, for example), I want to select and export to a new feature class. In order to do this, I will use the Field Values Iterator.
I can modify the options by double-clicking on the hexagon. I choose and Excel worksheet (PestSpeciesList$), and my “COM_NAME” field has all the unique values. I can also choose to skip null values or specify a value to ignore.
Once I’ve done this, the iterator now has all the information to loop through the dataset and select features based on the unique values in my spreadsheet.
Every time it loops through, it parses that unique value to a variable I can now use in other geoprocessing tools, as an In-Line Variable.
In-line variables are great because they allow you to automatically populate SQL queries, or automatically name file names based on the unique value chosen. All I need to do is input %Value% wherever I want the variable to be used. Remember that “Value” can be any name you give it, but it is the output of the iterator (green oval in image above).
In this case, I want to export those selected features to a new feature class, so I’m going to use the Feature Class to Feature Class tool. Any parameter that I would have had to individually specify, can now use the in-line variable.
Let’s recap – I started with a spreadsheet with 3 unique values. The iterator takes each of the three values using each entry under “COM_NAME”, and uses that unique value (%Value%) to select features and export to automatically named feature classes (“PestSurvey_Pricklyacacia”, “PestSurvey_Parthenium”, “PestSurvey_Lantana”).
Now this is a very simple example. I can build my complex workflows using modelbuilder, and rather than having to run the workflow repetitively, I can use an iterator as a loop. This is a really good resource for people like me, who don’t like to write scripts. If you need more than one iterator, you can employ nested models, but that is a whole other blog entry.
So go ahead and use those iterators, run that model, and grab a coffee while modelbuilder does the hard work for you.