Friday, 6 March 2015

arcobjects - Adding fields to raster attribute table


I have a raster attribute table associated with an IMAGINE .img raster that I build and open with:



IGPUtilities utils = new GPUtilities();
IRasterDatasetEdit2 raster = (IRasterDatasetEdit2)
utils->OpenRasterDatasetFromString(path);

raster.BuildAttributeTable();
ITable vat = (raster as IRasterBandCollection).Item(0).AttributeTable;

I need to add new column to the table and populate with values. However, calling AddField on the table throws "The method or operation is not implemented" exception.


IFieldEdit field = new FieldClass();
field.Type_2 = esriFieldType::esriFieldTypeString;

field.Name_2 = "Name";
vat.AddField(field as IField); // Throws

Is there a direct way how to modify the existing attribute table or do I have to create one on my own and assign it to the raster using IRasterDatasetEdit2::AlterAttributeTable()?


I'm using ArcObjects .NET SDK with ArcGIS 9.3.1.


Edited


Once again ArcMap behaves curiously: When I open the raster in ArcMap after my code failed to add the field, I can open the attribute table but the 'Add Field...' option is disabled. If I remove the raster and open it again, I can add fields from ArcMap and also my code works!


Everything works fine with GeoTiff images.


I do not think this is a locking issue since I'm releasing all COM instances (via System::Runtime::InteropServices::Marshal::ReleaseComObject())




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...