Select to view content in your preferred language

how to run a repeat function in Model Builder (loop? Iterator?)

1175
2
07-02-2022 11:59 AM
Labels (2)
linoyzagrizak
New Contributor

Hey all!

I designed a model using Model Bilder- in this model, and I'm using the "Random point" function. I want to set the model to run and, each time, change the value of the points until it reaches a specific value ( from 100 up to 10,000 exponentially).

After the random point function, there are more functions, so I need the model to keep running for the following functions according to the point values.

I looked at the "iterator" options, and I don't know if they suit what I'm doing. Maby I need to create a  loop, but I never did one using the model builder tool. 

I appreciate your help! 

 

0 Kudos
2 Replies
JayantaPoddar
MVP Esteemed Contributor

I assume you want to randomly fill the Field for "Number of Points" before running "Create Random Points" (inside a model builder). And the number of features in each polygon should change every time you run the model.

If my assumption is correct, you need to add a "Calculate Field" geoprocessing tool in the model, and connect it prior to "Create Random Points" tool.

Your Calculate Field expression (Python Parser) could look like this.

JayantaPoddar_0-1656791500337.png

 

Code Block

 

import random
def randnum():
    return random.randint(100, 10000)

 

Expression:

 

randnum()

 

 

My field looks something like this.

first run:

JayantaPoddar_1-1656791768132.png

 

second run:

JayantaPoddar_2-1656791841137.png

 

Your model will then use this field to create the specified number of random points.



Think Location
0 Kudos
linoyzagrizak
New Contributor

Hey Jayanta Poddar  , thank you for your answer.

I will focus on my question- this is my model (image attached). I have two rasters (same size and location), and I use the "random point" tool to extract the values of the rasters and operate the GWR tool from there. The number of points will affect the GWR tool.

I want to see the change in GWR as a function of the point number; this is why I want the point number to change to 10,000 gradually.

Is the  "Calculate Field" will would fit in this case? If I'm not using Python Parser how can I add the "Calculate Field" to my model?

linoyzagrizak_0-1656925472875.png

 

Thank you for being so helpful! 

0 Kudos