I too, have no small degree of problems writing out SHORT rasterdatasets on ArcGIS 10 (it worked for me also in ArcGIS 9.3). The best I've been able to do so far is to create a rasterdataset, then copy the file with properties set using the SaveAs functionality. This is a kludge, as the functionality should work as the interface indicates. The other wrinkle is that their documentation talks about autocorrecting the pixel type based on the data present. I've noticed this is often incorrect, but this is why I write out a few sample pixels first.
This is in my open method:
// This first creation of a raster dataset will result in a 32-bit dataset. According to the
// documentation, the resolution is automatically recomputed when adding data to the raster dataset.
IRasterDataset tempDataset = workspace.createRasterDataset(tempFileName,
"GRID",
originPoint,
width,
height,
cellSizeX,
cellSizeY,
noOfBands,
rstPixelType.PT_SHORT,
geographicCoordinateSystem,
false);
//Get the raster band.
IRasterBandCollection rasterBands = (IRasterBandCollection)tempDataset;
// IRasterBandCollection rasterBands = new IRasterBandCollectionProxy(tempDataset)
// ;
IRasterBand rasterBand = rasterBands.item(0);
IRasterProps rasterProps = new IRasterPropsProxy(rasterBand);
//Set NoData if necessary. For a multiband image, NoData value needs to be set for each band.
if (noDataValue != null)
{
rasterProps.setNoDataValue(noDataValue.shortValue());
}
else
{
rasterProps.setNoDataValue(-500);
} // end if
IRaster raster = tempDataset.createDefaultRaster();
IRasterProps rasterProps2 = new IRasterPropsProxy(raster);
rasterProps2.setPixelType(com.esri.arcgis.geodatabase.rstPixelType.PT_SHORT);
rasterProps2.setSpatialReference(geographicCoordinateSystem);
if (noDataValue != null)
{
rasterProps2.setNoDataValue(noDataValue.shortValue());
}
else
{
rasterProps2.setNoDataValue(-500);
} // end if
rasterProps2.setHeight(height);
rasterProps2.setWidth(width);
// Here we're writing out pixels to the tempDataset to keep the attribution as we want it
// when copied in the subsequent save as command
writeOutTokenPixels(raster);
IWorkspace tempWorkspace = new IWorkspaceProxy(rwf.openFromFile(this.workspaceName,
0));
ISaveAs saveAs = new ISaveAsProxy(rasterProps2);
// ISaveAs saveAs = new ISaveAsProxy(rasterBands);
saveAs.saveAs(gridFileName, tempWorkspace, "GRID");
// We need to open the newly copied raster to write a few pixels out to it...
this.rasterDataset = workspace.openRasterDataset(gridFileName);
// raster = this.rasterDataset.createDefaultRaster();
IRasterDataset2 rasterDataset2 = (IRasterDataset2)this.rasterDataset;
IRaster2 rasterF = new IRaster2Proxy(rasterDataset2.createFullRaster());
raster = new IRasterProxy(rasterF);
writeOutTokenPixels(raster);
EsriCleanerWrapper.releaseObject(this.rasterDataset);
this.rasterDataset = null;
This the logic in my write function:
double computedX = GridFileReader.determineXOffsetFromExtents(chunkExtent, this.cellSizeX, this.fileBounds);
double computedY = GridFileReader.determineYOffsetFromExtents(chunkExtent, this.cellSizeY, this.fileBounds);
//Create a raster.
IRasterDataset2 rasterDataset2 = (IRasterDataset2)rasterDataset;
IRaster2 raster2 = new IRaster2Proxy(rasterDataset2.createFullRaster());
// if (this.raster2 == null)
// {
// this.raster2 = new IRaster2Proxy(rasterDataset2.createFullRaster());
// } // end if raster2
//Create a pixel block.
IPnt blocksize = new DblPnt();
blocksize.setCoords(width, height);
// Allocate the rasterCursor if not already allocated
if (this.rasterCursor == null)
{
this.rasterCursor = raster2.createCursorEx(blocksize);
} // end if rasterCursor
// Move the cursor to the desired location
boolean foundChunk = GridFileReader.moveCursorToChunk(this.rasterCursor, computedX,
computedY);
if (foundChunk)
{
//Use the IRasterEdit interface to update the raster
IRasterEdit rasterEdit = new IRasterEditProxy(raster2);
IPnt tlc = this.rasterCursor.getTopLeft();
double tlcX = tlc.getX();
double tlcY = tlc.getY();
logWriter.debug("For computed=" + computedX + "," + computedY +
",tlc=" + tlcX + "," + tlcY);
IPixelBlock3 pixelblock3 = new IPixelBlock3Proxy(this.rasterCursor.getPixelBlock());
int blockwidth = pixelblock3.getWidth();
int blockheight = pixelblock3.getHeight();
pixelblock3.setPixelType(0, com.esri.arcgis.geodatabase.rstPixelType.PT_SHORT);
//pixelblock3.mask(255);
//Get the pixel array.
short[][] pixels = (short[][])pixelblock3.getPixelData(0);
for (int i = 0; i < blockheight; i++){
for (int j = 0; j < blockwidth; j++)
{
//Get the pixel value from the Object pixels.
pixels = rasterData;
} // for j
} // for i
//Set the pixel array to the pixel block.
pixelblock3.setPixelData(0, pixels);
IPixelBlock pblock = new IPixelBlockProxy(pixelblock3);
pblock.setPixelType(0, com.esri.arcgis.geodatabase.rstPixelType.PT_SHORT);
//Write back to the raster.
rasterEdit.write(tlc, pblock);
rasterEdit.refresh();
EsriCleanerWrapper.releaseObject(rasterEdit);
rasterEdit = null;
}
else
{
throw new CoreSystemException("LOGIC ERROR: Could not find chunk within GRID file");
}
Hope this helps someone...