Geoprocessing with ModelBuilder: Iterate Field Values

Recently, I’ve been doing a lot of geoprocessing in ArcGIS – both for data conversion operations and spatial analysis. My main tool here is ModelBuilder however I might use Python now and then if something cannot be done by using the out-of-the-box tools built in ModelBuilder. I thought to post some of the typical workflows I’ve been trying to automate; to let everyone use some public data available, I’ll use OSM (OpenStreetMap) data in the models.

A fist typical workflow is that you’ve got a shapefile (it can be a feature class in a geodatabase too) where several types of roads are stored and its name is Roads. Say, you have motorways, local roads, bicycle paths and so on. Your task is to create several shapefiles/feature classes which will contain only roads of certain type and will be named accordingly (Roads_Motorway, Roads_Bicycle etc.).

This is something that can be done manually in ArcMap by selecting first those features that match a certain definition query (“RoadType” = “motorway”) and then export those selected features to a new feature class (by right-clicking the layer in ArcMap and choosing Data > Export Data). However, if there are dozens of road type values available, this task might take longer time and it would be beneficial to automate it especially if this operation might be needed to be done not once yet multiple times with the upcoming shipped deliveries of Roads feature class.

Before ArcGIS 10, I’ve been using the Split By Attributes tool that Dan Patterson developed for some years ago. It is a Python script implemented as a tool in an ArcGIS toolbox. However, in ArcGIS 10, the new concept – iterators were introduced. There are quite a few iterators available to us, but for now we will focus just on a single iterator – Iterate Field Values – which will let us solve the problem with the road types.


By using the model below, we can do the following:
1)      Take the input Roads feature class and go through all values stored in the road type field;
2)      Take first value found (green oval with “Value”) and use the Feature Class To Feature Class GP tool to export those roads of a certain type to a new feature class by using the SQL-expression. The trick here is that we use the inline variable substitution to get the retrieved Value into the SQL-expression string and into the output feature class.
3)      Take second value found and do the things outlined above in the step 2.

And so it goes. The output of running the model would be multiple feature classes with the name Roads_motorway, Roads_highway, etc.

More useful resources on iterators in ModelBuilder is available at the Geoprocessing Model and Script Gallery – Working with Iterators in ModelBuilder – Tutorials.

Happy iterating!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s