Hi,
I'm having problems getting some code working in ArcGis 10, that had previous worked in 9.3.
I am generating a raster and then tryng to save it. If I save it as a GRID, everything is ok. But if I save it as TIFF or Imagine, no raster statistics get generated. For example, ArcMap / Layer Properties / Source says 'Statistics have not been calculated' and the symbology shows the range of values as 0-255 for a 8-bit raster. The raster (pixel) data appears to be saved correctly - it's simply missing the statistics.
I have simplified our code to produce a demonstration - see code below - almost identical for the working/failing cases. This is invoked in a BaseCommand in ArcMap.
Mike.
-----
private void test1b()
{
string foldername = @"C:\xxxxx\rasters";
#if false
// this works ok, with statistics in the Grid
string filename_temp = "testras_temp";
string filename_perm = "testras_perm";
string saveas = "GRID";
#else
// this produces a TIFF but with 'Statistics have not not calculated'
string filename_temp = "testras_temp.tif";
string filename_perm = "testras_perm.tif";
string saveas = "TIFF";
#endif
// geometry of new raster
Point por = new Point();
por.PutCoords(0, 0);
IPnt psize = new PntClass();
psize.SetCoords(100, 100);
// raster workspace ..
RasterWorkspaceFactory rwf = new RasterWorkspaceFactory();
IRasterWorkspace2 rws = rwf.OpenFromFile(foldername, 0) as IRasterWorkspace2;
// spatial ref ...
ISpatialReferenceFactory2 srefFact = new SpatialReferenceEnvironmentClass();
ISpatialReference sref = srefFact.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_BritishNationalGrid);
// create a raster dataset
IRasterDataset rds = rws.CreateRasterDataset(filename_temp, saveas,
por, (int)psize.X, (int)psize.Y, 1, 1,
1, rstPixelType.PT_UCHAR, sref, false);
// and the raster to be returned
IRaster ras = rds.CreateDefaultRaster();
// prepare for some pixels
IRawPixels rawpix = (rds as IRasterBandCollection).Item(0) as IRawPixels;
IPixelBlock3 pb = rawpix.CreatePixelBlock(psize) as IPixelBlock3;
IRasterProps rprop = (rds as IRasterBandCollection).Item(0) as IRasterProps;
rprop.NoDataValue = (byte)255;
System.Array pixelarray = pb.get_PixelDataByRef(0) as System.Array;
for (int col = (int)por.X; col < psize.X; col++)
{
for (int row = (int)por.Y; row < psize.Y; row++)
{
byte val = (col != row) ? (byte) rprop.NoDataValue : (byte) row;
pixelarray.SetValue(val, col, row);
}
}
pb.set_PixelData(0, (System.Object)pixelarray);
// write the raster to temp
IPnt porw = new PntClass();
porw.SetCoords(por.X, por.Y);
(ras as IRasterEdit).Write(porw, (IPixelBlock)pb);
// this just flushes the temporary raster
//(ras as IRasterEdit).Refresh();
// save a permanent raster
(ras as ISaveAs).SaveAs(filename_perm, rws as IWorkspace, saveas);
}