Hexagon Geospatial
MENU

ERDAS IMAGINE

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
Highlighted
Occasional Contributor
Posts: 8
Registered: ‎02-22-2018
Accepted Solution

Associate <root_name>.vat.dbf with Raster in ERDAS Imagine

[ Edited ]

I have an Arcpy script for ArcMap that adds a new column, 'crop', to the attribute table of a (.img) raster that was generated from an Imagine classification. When I try to reopen the raster in Imagine, the crop column isn't read in. Some folks at Hexagon pointed out to me that ArcGIS creates a file called <root_name>.vat.dbf alongside the image and this is where the new attributes are stored. Unfortunately, it appears that ERDAS IMAGINE doesn’t know about this file, so it doesn’t read the extra attributes (the new crop field). 

 

Here's the reason I'm looking to make this new column: I need to reclassify my raster and scale up my Class_Name groups. The Class_Names are very specific crop type subsets and I need to regroup into the broader crop groups in which they belong. Essentially I need to Recode the raster so that there is a new Class_Name that is based on the beginning of the third split in the old name (e.g. old Class Name 13675-0-14.06-0-2-1 becomes crop 14 and old Class Name 13985-24-14.03-0-2-1 also becomes crop 14).

 

I couldn't figure out how to do this in Imagine and so I wrote a python 2.7 script using Arcpy to edit the raster's attribute table in ArcMap. 

 

I am wondering how I can get Imagine to read in this <root_name>.vat.dat file so that I can view my newly edited attribute table in Imagine? Additionally, if there is a way to code this in python or SML to run in Imagine, I'd love to know how to do that as well.

 

import arcpyfrom arcpy.sa 
import *arcpy.env.workspace = arcpy.GetParameterAsText(0)
# Set output Folder
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension('Spatial')

in_raster = arcpy.GetParameterAsText(1) # 1. Add a field, 'crop' to the .img file
in_Features = in_raster field_name = 'crop'
field_type = 'SHORT'
arcpy.AddField_management(in_Features, field_name, field_type) # 2. Populate the field 'crop' with an integer value for the larger crop # group that the pixel belondgs to.in_table = in_Features field_names = ['Class_Name', 'crop'] with arcpy.da.UpdateCursor(in_table, field_names) as cursor: for row in cursor: if row[0] == 'Unclassified': row[1] = 'Unclassified' elif row[0] == ' ': row[1] = ' ' else: row[1] = row[0].split("-")[2].split(".")[0]

 

The script creates the new column in Arc:

enter image description here

 

But Imagine isn't reading it in:

enter image description here

 

New <root_name>.vat.dbf created by ArcGIS:

Capture.PNG

 

Technical Evangelist
Posts: 508
Registered: ‎10-01-2015

Re: Associate <root_name>.vat.dbf with Raster in ERDAS Imagine

The attached Spatial Model should add the new column and populate the attributes the way you want.

 

For quick reference, the model looks like this:

 

attribute.PNG

 

...with the Iterator doing this:

 

attr_iterator.PNG

 

 

Cheers

 

Ian Anderson
Chief Product Owner, Desktop Remote Sensing
Hexagon Geospatial
Occasional Contributor
Posts: 8
Registered: ‎02-22-2018

Re: Associate <root_name>.vat.dbf with Raster in ERDAS Imagine

Thanks so much Ian, this worked perfectly.

 

One last question though: how can I export the model as code? If I'm not mistaken the legacy .gmd graphical model could write a permanent script file through Model Maker > Process > Generate Script. I couldn't figure out how to do this with the new Spatial Model Editor from a .gmdx spattal model (such as the one you made).

 

Thank you!

Staff
Posts: 2
Registered: a month ago

Re: Associate <root_name>.vat.dbf with Raster in ERDAS Imagine

Hi,

 

The .gmdx is already a permanent script, just in XML rather than SML. There's no way to convert a .gmdx to the old SML language.

 

So I guess the real question is why you need to convert it a script / code? 

 

Cheers

 

Ian

Occasional Contributor
Posts: 8
Registered: ‎02-22-2018

Re: Associate <root_name>.vat.dbf with Raster in ERDAS Imagine

[ Edited ]

Hi, 

 

Thanks so much for that info. I was hoping in general to learn how to code for IMAGINE. One of our projects has a long workflow with steps that jump back and forth between different programs and scripts. The steps for this model are a piece in the middle. I was hoping to learn how to code for IMAGINE so that I can streamline as much of our process as possible and avoid bouncing between software programs. The option to make a model is great, but code is a little more intuitive for me. I basically leared python from exporting the model scripts from ArcGIS and was wondering if I could use that same method to learn a coding language for IMAGINE. I have a follow up question about languages, and posted it in a new topic string https://community.hexagongeospatial.com/t5/ERDAS-IMAGINE/Language-for-IMAGINE/m-p/27560#M2342

so that its searchable for anyone with the same question. 

 

Thanks a million!

 

Technical Evangelist
Posts: 508
Registered: ‎10-01-2015

Re: Associate <root_name>.vat.dbf with Raster in ERDAS Imagine

I'll let others in the community post their experiences, but Python is certainly a good option. Unfortunately we don't currently have an option to Save As... a .gmdx to a python script. That'd certainly be a good suggestion to post to the Ideas forum.

 

Cheers

Ian Anderson
Chief Product Owner, Desktop Remote Sensing
Hexagon Geospatial
Do you need immediate support?
If you encounter a critical issue and need immediate assistance please submit a Service Request through our Support Portal.