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()
)
-
1Does arcmap allow you to manually add a field to an img based raster?Kirk Kuykendall– Kirk Kuykendall2011年08月29日 15:04:30 +00:00Commented Aug 29, 2011 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– Martin Gunia2011年08月29日 15:14:46 +00:00Commented Aug 29, 2011 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– Kirk Kuykendall2011年08月29日 16:29:30 +00:00Commented Aug 29, 2011 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– Martin Gunia2011年08月30日 06:03:55 +00:00Commented Aug 30, 2011 at 6:03
-
Did you try calling ReleaseInternals?Kirk Kuykendall– Kirk Kuykendall2011年08月30日 12:48:48 +00:00Commented Aug 30, 2011 at 12:48
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.
-
1I'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– Martin Gunia2011年08月29日 13:42:56 +00:00Commented Aug 29, 2011 at 13:42
Explore related questions
See similar questions with these tags.