I am trying to change the a raster's NoData value with ArcObjects and keep coming up short.
Here is the code that I thought would work:
IRasterDataset _dataset = ...get the dataset...
object[] noDataValue = ...set the no data values by raster band...
var rasterbandCollection = (IRasterBandCollection) _dataset;
for(int i = 0; i < rasterbandCollection.Count; i++)
{
((IRasterProps) rasterbandCollection.Item(i)).NoDataValue = noDataValue[i];
}
This value persists during the ArcMap session, but does not save the changes to disk it appears. Any ideas on how to make this permanent (without having to save a second raster dataset)?
2 Answers 2
If you read the Help on the IRasterProps Interface is says
These modifications only affect the in-memory raster representation and in no way change any of the raster dataset. You can persist the modifications to a new raster datast using ISaveAs::SaveAs or IRasterBandCollection::SaveAs
So you can't just change it without creating a new raster dataset.
-
I did read that and thought that was applying to a in memory instance (which I was hoping to get around by going with the raster band). That is probably the answer, was just wishing it wasn't.Erik L– Erik L2012年06月07日 21:37:15 +00:00Commented Jun 7, 2012 at 21:37
if you set nodata in a rasterdataset store in disk you can change the nodata permanent
rasterBandCollection = rasterDataset as IRasterBandCollection;
rasterBand = rasterBandCollection.Item(0);
rasterProps = rasterBand as IRasterProps;
rasterProps.NoDataValue = -9999;