Spatial Modeler Discussions

Gain, exchange, and share knowledge, or discuss topics with other Hexagon Geospatial Product pioneers and experts to get the most out of Hexagon Geospatial products.
Showing results for 
Search instead for 
Do you mean 
Reply
New Contributor
Posts: 3
Registered: ‎04-11-2018
Accepted Solution

Is it possible to add a second condition to a Conditional-operator using python

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.

Staff
Posts: 3
Registered: ‎06-30-2016

Re: Is it possible to add a second condition to a Conditional-operator using python

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()
New Contributor
Posts: 3
Registered: ‎04-11-2018

Re: Is it possible to add a second condition to a Conditional-operator using python

Tnx! This was exactly what I was looking for.