ArcGis Model Builder: FOR and WHILE iterators

In the previous article ( ArcGIS Model Builder: expand a model to a set of input data ) we have addressed the most common iterators used with Model Builder. These iterators make it possible to apply a processing model to a set of input layers.

But there are two other types of iterators available:

  • the iterators FOR and WHILE
  • the iterators that browse entities of a single layer

In this article we will discuss the iterators FOR and WHILE

FOR Iterator

You will use this iterator if you want to run the process for a series of values. For example, you want to calculate a buffer of a certain distance and execute a process. Instead of testing several values ​​individually, you can decide to make buffers from 500 to 5000 meters with a 500m step. The model will run 10 times, the first time with a value of 500m for the buffer, the second with a value of 1000m, and so on.

If we use the ArcGis Resource Centre definition, the FOR iterator :
Performs iteration on a start value and an end value based on a given value. It behaves as any iterator for any programming language / script. It performs the iteration on a defined number of elements.

So that’s the equivalent of
for num in range ( 500,5000):                                          In Python
num = num + 500

For num As Double = 500 To 5000 Step 500              In VB.NET

How to change the output names of the model?

So that, in each iteration, the resulting layer has a different name (if not each consecutive output overwrites the previous one) you must add a variable element in the name.

By opening the last tool of a model, we always have the field “Output”, where you will define the location and name of the resulting layer. Let’s see the following example:

C: \ Users \ admin \ Documents \ ArcGIS \ Projects \ MyProject10 \ HYDROGRAPHIE_SURFACIQUE.shp

The element to add to the name of the output layer is none other than the value of the iterator (VALUE). To insert VALUE into the name of the output layer, simply set VALUE between% to the desired place in the name string, for example:

C: \ Users \ admin \ Documents \ ArcGIS \ Projects \ MyProject10 \ HYDROGRAPHIE_SURFACIQUE_% VALUE% .shp

At each iteration% VALUE% will be substituted by the name of the input layer.

WHILE Iterator

Here we face a dilemma, because this iterator has never served in any model. A search in the WEB does not find any example of use. So here we have to explain why it does not serve and not how it serves!

If we use the ArcGis Resource Centre definition, the WHILE iterator:
Works exactly like the instruction “whilein any script / programming language, and that is executed as long as a condition is either true or false for the input or set of inputs.

The problem is that in the programming languages, this operator is used on sequential operations. For example, you will read the records of a file UNLESS you do not arrive at the end of the file. Or process the records as long as the date is previous to the deadline, etc.
But this presupposes that the input data of the iteration follow a known and controlled order.
And in the case of Model Builder models, this is not the case, or it is not necessary to use this type of instructions.

Needless to say, the end of the file is a concept missing from the toolbox! But for the example of the deadlines, it is enough to make a selection on the date to retain only the desired dates. No need to sequentially browse records until a certain date.

The rare mentions of this iterator on the forums are regarding attempts to use it in cases where it does not apply.

So, are there any cases where it can be used?
The answer is yes, but they are rare. It must first be understood that the condition to be tested must be a condition external to the model. For instance, a time-related condition.
If you want to run the model for less than one hour, or for a given period of time. We must convey that these scenarios are rare, but this is the only example that comes to mind where we could use this iterator.

In any case, what you absolutely must not do is connecting the output of the iterator to the rest of the model: you can indicate the output as precondition of a tool but if the condition is fulfilled, the model will stop at the end of the current execution.

See you in the next article to see the latest type of iterator available with Model Builder.

Si cet article vous a intéressé et que vous pensez qu'il pourrait bénéficier à d'autres personnes, n'hésitez pas à le partager sur vos réseaux sociaux en utilisant les boutons ci-dessous. Votre partage est apprécié !

Leave a Reply

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