IMAGINE Discussions

Discuss and share topics of interest using ERDAS IMAGINE the world’s leading geospatial data authoring system.
Showing results for 
Search instead for 
Do you mean 
Reply
Occasional Contributor
Posts: 16
Registered: ‎10-05-2020
Accepted Solution

Erdas Imagine Raster Tool to Python Code

Hi Everyone, 

 

I'm looking for advice on the syntax to convert Erdas Imagine tools into Python code. I've seen the 2020 Erdas Example Scripts but I'm still lost. 

 

As an example I'm trying to convert the Unsupervised Classification tool into Python code.

 

The required inputs are: 

  • Input File
  • Output Cluster Layer File In
  • Number of Classes
    • Integer
  • Method Type 
    • Either 'K Means' or 'Isodata'

 

Two things: 

  • There's quite a few Non-required inputs inbetween all the required inputs, do I need to include something like 'None' inbetween the required inputs or can I just bunch them all together? 
  • Is there specific syntax for entering the Number of Classes (Ex: '10') and Method Type (Ex: 'K_Means' or 'K Means', etc.)

 

 

If there's anything I said that was confusing or incorrect I would be happy to re-clarify, just trying to figure out how the syntax is setup for Erdas Tools. 

 

Thanks, 

Mase

Occasional Contributor
Posts: 16
Registered: ‎10-05-2020

Re: Erdas Imagine Raster Tool to Python Code

I attempted to call the property names like such: 

 

Unsup = m.UnsupervisedClassification(InputFile=inp, OutputClusterLayerFileIn=Class_Band8, 
NumberofClasses='10', ClassifyZeros=True, MethodType='K Means') m.Execute()

However, it came back with a RuntimeError: unidentifiable C++ exception and if I try to use m.Preview(Unsup), it comes up with a: 'erdas::sb_ExecutableLibrary:XMLRExecutableOperator:Smiley TongueostRun Failed'. Not a lot to go off of for error checking. 

Occasional Contributor
Posts: 16
Registered: ‎10-05-2020

Re: Erdas Imagine Raster Tool to Python Code

[ Edited ]

I was able to figure it out!

 

I tried to replicate this process with other tools but couldn't get it. 

 

Steps:

  • In Erdas Imagine, open a new Spatial Modeler and drag the Unsupervised Classification in. 
  • Double click on the tool and enter all the information like you would normally. 
  • Hit 'Ok' 
  • All the information and proper syntax names will appear in the Properties pane (as seen in the attached image)

ErdasTooltoPython.PNG

 

 

 

The correct code would then be: 

 

 

Unsup = m.UnsupervisedClassification(InputFile=inp, OutputClusterLayerFileIn=Class_Band8, NumberofClasses='10', ClassifyZeros=1, MethodType='kmeans')

m.Execute()

 

 

The InputFile is just a '.tif' and the OutputClusterLayerFileIn is the output '.tif'.