CreateRasterDataset in Geodatabase

606
2
Jump to solution
09-30-2013 01:52 PM
TerryGiles
Occasional Contributor III
using C#, visual studio 2010, ArcGIS 10.1 -

I'm using the following code to create a new RasterDataset in a file geodb -

                //create                 IRasterWorkspaceEx rWS = (IRasterWorkspaceEx)ws;                 IRasterStorageDef2 rStorage = new RasterStorageDefClass();                 rStorage.CellSize = new Pnt(){X=cellsize,Y=cellsize};                 rStorage.Origin = origin;                 IRasterDef2 rDef = new RasterDefClass();                 rDef.SpatialReference = srOut;                 rds = (IRasterDataset2)rWS.CreateRasterDataset(strName, 1, ptype, rStorage, "", rDef, null);


This works, but the output RasterDataset is only 1 pixel big.  When you call CreateRasterData through IRasterWorkspace (for file based rasters) you can specify the width and height.  Basically I have a 2d array I'm trying to write into the raster - how do I do this when the output is only 1 pixel big?

I've tried casting to IRasterProps and changing the Width and Height props but that throws a COMException even though in the help they look to be read/write props -

                IRasterBandCollection rbc = (IRasterBandCollection)rds;                 IRasterProps rProps = (IRasterProps)rbc.Item(0);                 rProps.NoDataValue = nodataval;                 rProps.Width = Data.GetLength(0);  //Error here                 rProps.Height = Data.GetLength(1);


A push in the right direction would be appreciated!

Thanks, Terry
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
Have you tried IRasterWorkspace2.CreateRasterDataset?  It has input params for the number of rows and columns.

View solution in original post

0 Kudos
2 Replies
NeilClemmons
Regular Contributor III
Have you tried IRasterWorkspace2.CreateRasterDataset?  It has input params for the number of rows and columns.
0 Kudos
TerryGiles
Occasional Contributor III
Thanks Neil,

the ArcObjects help is not very clear on that.  Actually it is clear, it says

IRasterWorspace2 is used to access a raster stored in a file system in any supported raster format. To access raster from geodtabase, use IRasterWorkspaceEx interface.


Reading that, I assumed it would create a tiff file (or whatever format I passed in as the Format parameter) in the folder of my file geodatabase, but testing with my existing code that uses IRasterWorkspace2 seems to work properly.
0 Kudos