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()
)
Best Answer
I am not an ArcObject users but basically it should not possible to add a field to a raster. Conceptually you can't, since a raster is a grid with one value in the cell. You can only clone the raster and change the value of each cell.
Hote it helps.
Y.