10-17-2018 10:14 AM - edited 10-17-2018 10:19 AM
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
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 == 'Unclassified': row = 'Unclassified' elif row == ' ': row = ' ' else: row = row.split("-").split(".")
The script creates the new column in Arc:
But Imagine isn't reading it in:
New <root_name>.vat.dbf created by ArcGIS:
Solved! Go to Solution.
10-17-2018 11:03 AM
10-17-2018 03:17 PM
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).
10-18-2018 06:27 AM
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?
10-18-2018 10:01 AM - edited 10-18-2018 10:07 AM
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!
10-19-2018 05:46 AM
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.