02-20-2019 06:26 AM
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:
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) + '\\data\\' outputPath = os.path.dirname(sys.argv) + '\\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
Solved! Go to Solution.
02-21-2019 12:03 AM
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.
02-21-2019 12:50 AM
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?
02-21-2019 12:59 AM
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)
cmdCommand = "smprocess.exe <model> <model parameters>" #specify your cmd command
process = subprocess.Popen(cmdCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
04-08-2019 06:37 AM
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!