03-06-2020 05:48 AM
Hi
I know how create spatial models from scratch using python, and when doning this it's easy to add a Conditional-operator.
conditional = modeler.Operator(m, 'Conditional', Test1=<someRaster>, Value1=<someOtherRaster>)
But I havn't figured out how to add a second condition using python.
In the Spatial Model Editor it's possible to click the "Add port" option on several operators. What I really want to know is how to do this using python.
Solved! Go to Solution.
03-06-2020 11:02 AM
The Expand function will do the same thing as adding a port in Spatial Model Editor. Here's an example of its use.
from imagine import modeler m = modeler.Model() rasterInput = m.RasterInput(Filename="d:/work/lanier.img") rasterInput2 = m.RasterInput(Filename="d:/work/lanier.img") conditional = modeler.Operator(m, "Conditional", Test1=rasterInput, Value1=rasterInput2) # Equivalent to adding a port in the UI conditional.Expand() # If connecting new port to a port upstream conditional.ConnectParent(rasterInput.GetPort("RasterOut"), conditional.GetPort("Test2")) # If setting a value on the new port conditional.GetPort("Value2").data = "1" rasterOut = m.RasterOutput(conditional, "d:/work/newOutput.img") modeler.Solution.Save(m, "d:/work/model.gmdx") m.Execute()
03-10-2020 09:26 AM
Tnx! This was exactly what I was looking for.