Select to view content in your preferred language

Using iterations in modelbuilder

1862
10
Jump to solution
08-12-2012 02:43 PM
PeterThomsen
Emerging Contributor
Hi guys

I couldn't really figure out in which forum to ask this, so I'll try here.
Basically I need to run a model from modelbuilder 20 times where the final output of each run is used as the starting input in the next run. I've should either use the while or for iteration I guess, but I can't really figure out how to implement them in the model.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChristopherThompson
Frequent Contributor
There is a property on a variable you specify in model builder called the Feedback variable - I think this is what you want to use.  I haven't made use of this myself but from the help it sounds like this is the direction you want to go.. take a look here:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002w00000065000000

If you find a solution, post what it was as this is an interesting problem.

View solution in original post

0 Kudos
10 Replies
SolomonPulapkura
Frequent Contributor
What is it you are trying to do? Can you provide some more detail?
0 Kudos
BruceBacia
Frequent Contributor
Yes, if you can describe the problem more specifically, that would be great.  Have you looked at the help section?  http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00400000001n000000.htm
0 Kudos
PeterThomsen
Emerging Contributor
Ok, well I have built a simple model that describes the expansion of a city in a year from two parameters, as seen in the image.

[ATTACH=CONFIG]16869[/ATTACH]

The trick is that I need to make the model calculate how the city will expand through 20 years, meaning that the output of the first run needs to be the input of the next run, as the expansion of the city in year 1 should be taken into consideration when the expansion for year 2 is being calculated and so forth.
0 Kudos
BruceBacia
Frequent Contributor
How about trying the "For" iterator, as described in the documentation link.  It seems like it would work.
Set the From Value To 1
Set the To Value to 20
Set the By value to 1

You would want to tie the numeric value of each iteration to the raw path of the input file (starting with a pre-named "your path\map1.asc") using inline Variable substitution.  The model should dynamically draw the file by its full path, not as a fixed feature layer. 
You would then tell the model to name the output file with the numeric value of the iteration + 1, (yourpath\map2.asc)
On the following iteration, the input file would be the previous iteration's output file (yourpath\map2.asc) and the output file would be (yourpath\map3.asc)
This would repeat itself 20 times, with (yourpath\map21.asc) being the desired output.

Hopefully these ideas help.  I'm more familiar with python scripting.  With modelbuilder, sometimes doing what you think should be a simple task can turn out to be a real headache.
0 Kudos
PeterThomsen
Emerging Contributor
Thanks for the reply.
I have been trying to do something similar, though the "iteration +1" part didn't seem to work, but that is probably just me not knowing the exact way to write the command in modelbuilder. "Iteration +1" did also seem to cause problems in the raster calculators, as the tool could not recognize the layer, but again that is probably because I have written the "iteration +1" command wrong.
It seems like I wasn't too far off. Now I just need to figure out how to write the command properly. I will give it another shot.
0 Kudos
PeterThomsen
Emerging Contributor
I tried once more, and I got a basic "for" function to work, though I am still not able to add the iteration number by one. At the moment i write "map%value+1%" which does not seem to work. Furthermore Raster Calculator apparently does not like to use layers in the calculation that includes %value%, so I do not really know what to do.
0 Kudos
BruceBacia
Frequent Contributor
I tried messing with the for loop model iterator as well, and it seems you can't pass a dynamic file path to a geoprocessing tool, because the "file path doesn't exist".  Can you export your model to python script and post on the forum?  You can do this with the model open by going to Model > Export > To Python Script.   It would probably be a snap to add in the iteration number to the file path name and draw that into the process. 

If you do end up posting it, can you include the raw file path of map.asc?
Also, what is the output of the raster calculator tool?  If it is a new .asc file then you should be in business.
0 Kudos
ChristopherThompson
Frequent Contributor
There is a property on a variable you specify in model builder called the Feedback variable - I think this is what you want to use.  I haven't made use of this myself but from the help it sounds like this is the direction you want to go.. take a look here:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002w00000065000000

If you find a solution, post what it was as this is an interesting problem.
0 Kudos
BruceBacia
Frequent Contributor

There is a property on a variable you specify in model builder called the Feedback variable - I think this is what you want to use. I haven't made use of this myself but from the help it sounds like this is the direction you want to go.. take a look here:


Thanks for the link clthompson.  This looks like exactly what we need.  Many thanks
0 Kudos