[GRASS-user] gui modeler: dynamic variable names

Moritz Lennert mlennert at club.worldonline.be
Fri Nov 9 06:21:11 PST 2012


Hi,

I'm experimenting with the gui modeler (thanks for a great tool by the 
way !) trying to build a very simple model of city growth, starting with 
a very basic cellula automata style model where the state of each pixel 
at time t+1 depends the state of its neighborhood at time t.

In Python the result is as follows:


     for map in range(1995,2005):
         grass.run_command("r.neighbors",
                           overwrite = True,
                           input = "city",
                           output = "tmp1",
                           method = "sum",
                           size = 3)
         grass.run_command("r.mapcalculator",
                           overwrite = True,
                           amap = "city",
                           bmap = "tmp1",
                           formula = "if(A==0 && B>4, 1, A)",
                           outfile = "city",
                           help = "-")


Now I would like to keep each of the intermediate steps, and so create 
mapnames dynamically with the year in the map name. In Python I can do 
this like this:

     for map in range(1995,2005):
         grass.run_command("r.neighbors",
                           overwrite = True,
                           input = "city_"+str(map),
                           output = "tmp1",
                           method = "sum",
                           size = 3)
         grass.run_command("r.mapcalculator",
                           overwrite = True,
                           amap = "city_"+str(map),
                           bmap = "tmp1",
                           formula = "if(A==0 && B>4, 1, A)",
                           outfile = "city_"+str(map+1),
                           help = "-")

but is there a way to do this in the modeller directly ?

Moritz


More information about the grass-user mailing list