Is it possible to dynamically construct a Map Algebra expression that is dependent on the output of another tool, either using model builder or arcpy? For example, say I have a model that performs a raster reclassification that has a list of raster inputs and their respective outputs, i.e.
rasterOne -> reclassification -> outputRasterOne
rasterTwo -> reclassification -> outputRasterTwo
EDIT: To clarify, the number of input rasters is not known and therefore the number and names of the output rasters are not either. Because of this, I cannot hardcode them into the map algebra expression.
I would then want the map algebra expression to be similar to:
%"outputRasterOne"% + %"outputRasterTwo"% + ...
Best Answer
I've accomplished this in .NET by declaring optional inputs and then using an IF statement to decide whether or not to add additional rasters.
You have to do some fiddling with the input Map Algebra string (sMapAlgebra in my example) so that the optional parameters are either included or excluded. I do this outside of the method above, but you could create the string based on the IF statement. If you have a known limit to the number of input rasters (e.g. 3) you could just create 3 possible strings and choose one based on the number of actual parameters. However, this solution becomes bulky if you have many (say... > 10) possible input rasters.
In the same way you could determine the number of output parameters (e.g. IF you have 3 input rasters create 3 associated output rasters, maybe by appending "out" to the raster name, e.g. "R1_out" in my example. You could just create these inside of the conditional statement.