11. Developing an Iterative Framework

 
Subtitles Enabled

Sign up for a free trial to access more free content.

Free trial

Overview

You will learn how to configure an iterative macro so that you can run multiple queries in order to determine an optimal result. In this first lesson, you will learn how to configure the iterations required.

Lesson Notes

Iterative Macros

  • Iterative macros continually adjust a parameter until a condition is met
  • The Engine.IterationNumber is a constant that corresponds to the number of times a macro has run

Transcript

In the previous lesson we created a batch macro that allows us to perform a repeat process on the workflow. In the next two lessons we'll take a look at a different type of macro known as the iterative macro. An iterative macro preforms a calculation or a process many times until a specific condition is met. The macro will gradually adjust the process for each iteration of the calculation as specified by the user.

This concept can be a bit tough to grasp on its own so let's run through an example. In the course on spacial analysis we introduced the airport and hotel datasets. In that course we worked out that if we wish to calculate the number of hotels within a certain distance of an airport we can use the trade area tool. What if instead we wanted to know the smallest trade area around each airport that captured the nearest 10 hotels from our hotel dataset? We can't specify a set distance from each airport for our trade area as an airport near London may have 50 hotels within a five mile radius while an airport in the Lake District might only have one or two.

To answer this question we need to draw a small circle around each airport in our dataset and then count how many hotels fall within that area. If the number of hotels is less than 10, we can increase the size of the circle and count again. We'll then repeat this exercise until we satisfy our condition of 10 hotels for that airport. Manually performing this exercise for each airport in our dataset could be quite inefficient. However, the iterative macro is ideal for the task. In this lesson we'll develop a framework for our iterative macro. We'll accomplish this goal by following three key steps. First, we'll change the file type of our workflow to iterative macro. Next, we'll create trade areas for our airports. Finally, we'll match the hotels in our dataset with our airport trade areas. We'll start by changing the file type of our workflow. On a new canvas we'll go to the Workflow tab on the configuration window and change the type to iterative macro. We're now ready to move on to step two and create trade areas for our airports. We'll start by navigating to the Interface tab and bringing down a macro input tool. In the configuration window we'll select file input and point the tool to our airport dataset. We'll then name this tool Input and assign the anchor abbreviation I. We'll run the workflow and see that we have a list of 97 airports with altitude and longitude information. We need to convert these into geographic points or centroids, so we'll navigate to the Spacial tab and connect a create points tool. At this point we need to think ahead and consider how large our trade area should be for each iteration.

In this case we'd like our trade areas to increase by a quarter of a mile for each iteration starting at 0.25 miles.

We can easily accomplish this with the formula tool. To that end we'll connect a formula tool to the workflow and create a new field called Area Size. In the canvas we'll enter the constant Engine.IterationNumber multiplied by 0.25 and add 0.25.

We'll then change the data type to FixedDecimal size 12.2.

The Engine.IterationNumber is a constant that returns a number corresponding to each iteration of the macro. For example, on the first iteration the engine iteration number will be one while on the 10th iteration it will be 10. We've multiplied this constant by 0.25 since we want to increase our trade area in quarter mile steps.

Also, note that the constant starts counting at zero as the first iteration is actually the second time through the workflow.

That is to say this formula will return an area size of 0.25 miles for the first iteration, 0.5 miles for the second and so on.

This should make a bit more sense as we see it in action. Next, we'll bring a trade area tool onto the canvas and reference the centroid we created earlier. We'll then set the radius to pull from the field Area Size that we just created.

This means that the trade area will begin with a area radius of 0.25 miles and then iterate on that number going to 0.5 miles, 0.75 miles etc.

It's important to note that the radius we iterate on becomes the radius of the first circle. We'll revisit this wrinkle later in the workflow. At this point our tool will create trade areas around our airports. We're now ready to move onto step three and match our hotel dataset with our trade areas. We'll bring down an input data icon, point it to the hotel dataset, and then connect a create point tool to turn that information into spacial data. In order to see where hotels are contained within the trade areas, we'll bring down a spacial match tool. The target input is the trade area with the universe being the hotel centroids. In the configuration window we'll ensure that the target is a spacial object trade area, the universe is centroid and that the tool will search for where the target intersects the universe. Now that we've imported all the relevant data we'll stop here and recap the lesson. First, we changed the file type of our workflow to iterative macro. Next, we created trade areas for our airports. We made use of the Engine.Iteration constant to ensure that our trade area will increase by a quarter of a mile for each iteration of the macro. Finally, we connected our hotel dataset and matched the hotels with our airport trade areas. In the next lesson we'll verify our success threshold and specify how the macro should iterate on elements that do not meet that threshold.