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
Frequent Contributor
Posts: 158
Registered: ‎03-04-2016
Accepted Solution

Path to ERDAS IMAGINE can not be resolved

Hey community,

 

I'm new to using Python to load and execute a spatial model.

I've created one exploiting GEOSYSTEMS Germany UAV operators in the editor and then saved it. I was able to run that model in batch mode with success.

However when i call it from my python code, I get an error i can't even understand:

 

RuntimeError: HexGeo::SpatialModeler::Operator::Execute failed
HexGeo::SpatialModeler::Operator::SetErrorMessage failed
Spatial Model failed in Export Mosaic.  The error was "Path to ERDAS IMAGINE cannot be resolved".

I've tried to use input port / no input port, and tried every option in the book regarding the output path/name with no success.

 

Does anyone have an idea of what might be the issue here?

I will be glad to share my model but it does not work without a UAV Workflow license. 

Here is a screen shot of the model:

Model.JPG

And here is my python code:

import sys, os
from imagine.modeler import Model, Operator, Solution

# Get directories for input and output data,
# based on where this script is located.

dataPath = os.path.dirname(sys.argv[0]) + '\\data\\'
outputPath = os.path.dirname(sys.argv[0]) + '\\output\\'
if not os.path.exists(outputPath):
    os.makedirs(outputPath)
print('Donnée en entrée ' + dataPath)
print('Dossier de sortie ' + outputPath)

# Load a saved model
modelFile = outputPath + 'fouilles3d_elo.gmdx'
m = Solution.Load(modelFile)

# Display everything
print (m)

# Trouver les opérateurs et changer les noms des fichiers et dossiers

projet = next(op for op in m.GetOperators() if op.name == u"CreateProject")
projet["ImageDirectory"] = dataPath

projet = next(op for op in m.GetOperators() if op.name == u"CreateProject")
projet["OrientationDataFile"] = dataPath + 'OE.txt'

ortho = next(op for op in m.GetOperators() if op.name == u"ExportMosaic")
ortho["MosaicName"] = outputPath + 'ortho.tif'

las = next(op for op in m.GetOperators() if op.name == u"ExportLAS")
las["LASName"] = outputPath + 'nuage.las'


for op in m.GetOperators():
    print (op)

for port in op.GetPorts():
    print (port)

# Run the model
m.Execute()
print('Exécution terminée ' + modelFile)

Thanks in advance for the help

Kind regards,

Elodie

Occasional Contributor
Posts: 11
Registered: ‎11-02-2015

Re: Path to ERDAS IMAGINE can not be resolved

Hi Elodie,

 

It looks like that the determination of the IMAGINE path within some of the UAV operators is to tightly linked to the way a Spatial Model gets executed. In the context of executing from within Python that determination seems to fail. This is a bug and will be fixed in the next release. For the meantime, a possible workaround is to start the smprocess as external process from within the python environment.  I know that takes away the whole idea of the python integration, but should do the job for the time being.

 

Best regards,

Thomas

Frequent Contributor
Posts: 158
Registered: ‎03-04-2016

Re: Path to ERDAS IMAGINE can not be resolved

Hi Thomas,

 

Thanks for your answer. 

I'm not sure I understand the workaround.

So can you explain your idea a bit more? 

And also what is the date for the next release?

 

Kind regards,

Elodie

Occasional Contributor
Posts: 11
Registered: ‎11-02-2015

Re: Path to ERDAS IMAGINE can not be resolved

Hi Elodie,

 

Instead of assembling the inputs and calling the model from within python you can just build the equivalent command line for smprocess and execute it as external sub process. There are several python modules allowing you to do that.  (e.g. subprocess)

 

e.g:

 

import subprocess

cmdCommand = "smprocess.exe <model> <model parameters>"   #specify your cmd command

process = subprocess.Popen(cmdCommand.split(), stdout=subprocess.PIPE)

output, error = process.communicate()

 

Thomas

Frequent Contributor
Posts: 158
Registered: ‎03-04-2016

Re: Path to ERDAS IMAGINE can not be resolved

Thomas,

 

This is a lot more clear. I will try that then.

Finger crossed.

What about the release date though Smiley Happy

 

Elodie

Occasional Contributor
Posts: 11
Registered: ‎11-02-2015

Re: Path to ERDAS IMAGINE can not be resolved

I can't give you a specific release date as of now but we will release an update during spring. 

Thomas

Highlighted
Occasional Contributor
Posts: 11
Registered: ‎11-02-2015

Re: Path to ERDAS IMAGINE can not be resolved

Hi Elodie,

 

An update of IMAGINE UAV is now available. You can download it from our website. With that version you should be able to run the operators from python directly!

 

Best regards,

Thomas