Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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())

share|improve this question
1  
Does arcmap allow you to manually add a field to an img based raster? –  Kirk Kuykendall Aug 29 '11 at 15:04
    
Only when I remove the raster my tool created and open it again. That suggests that something isn't quite finished (my code ends with exception but I make sure I'm releasing the underlying COM instances). –  Martin Gunia Aug 29 '11 at 15:14
    
Did you try calling IDataLayer2.Disconnect then IDataLayer2.Connect ? Also, interactively, did you try killing your ArcSOCp.exe process? Maybe it has a lock on the raster. –  Kirk Kuykendall Aug 29 '11 at 16:29
    
@Kirk: Thanks. The result of my tool is not a layer, it is a newly created raster. After my tool finishes, only then I open it as a layer in ArcMap and have the 'Add Field...' option disabled. Removing and opening fixes the problem. This does not happen with GeoTIFF images so I can go around using those, I'm just being curious now why .img won't work normally :) If I understand right ArcSOCp.exe is related to ArcGIS10 background processing? I'm still using ArcGIS 9.3. –  Martin Gunia Aug 30 '11 at 6:03
    
Did you try calling ReleaseInternals? –  Kirk Kuykendall Aug 30 '11 at 12:48
add comment

1 Answer 1

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.

share|improve this answer
1  
I'm not trying to add fields to the raster but to its attribute table (that is a normal table having one row for each qnique value in the raster). It works for GeoTIFF rasters but not for IMAGINE rasters. –  Martin Gunia Aug 29 '11 at 13:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.