how to generate name of raster

12-05-2013 12:21 AM
Occasional Contributor III

I'm developing a model in which I take two rasters as input, do some rastercalculation and produce a third raster.

As long as I provide a name for this resulting raster in the "output raster" field of the rastercalculator everything is fine.

Now I would like to automatically generate the name of the resulting raster from parts of both input names so later I can determine from the name which rasters were used as input. (All my input rasters have a strict name convention)

Basically I'm trying to generate a string which I can then use as inline variable in the output raster box of the rastercalculator, something along the lines of:
output1 = (value1[2:4]+value1[6:7]+value2[2:4]+value2[6:7])

First I've tried this with the model only tool "calculate value" but no succes, perhaps I cannot create a string using this tool?

Secondly I tried to write a scripttool which generates an output string from two inputs, seems  to work on itself but whatever I try I cannot get it accepted in the rastercalculator' output raster field. It's either ignored or I get the value '1' filled in

    Is there anybody who can point me towards what I'm missing here?
    Should a string work?
    Can I generate a string using 'calculate value'?
    Am I overlooking another tool which is capable of manipulating strings like I want?
    Should I avoid using strings altogether and think differently? (how?)
Any help is greatly appreciated (I'll mention you in my documentation :-)) and one day I hope to return the favor.


0 Kudos
1 Reply
Occasional Contributor III
Took some time but here is my solution using 'Calculate Value':


Using 'parse path' and choosing NAME I get two strings in Value1 and Value2.

These are both preconditional for the 'calculate value'

Pay ATTENTION to the double quotes around the %variables% in the expression; they costed me most of the day 😉
So the expression is:
x("%Value1%", "%Value2%")

The code block concatenates some parts of the original names into a decriptive name which is used to name the resulting raster (example above is from a test model which doesn't do much beside create the output_value)

Works like a charm, hope this will be helpful for someone.


0 Kudos