Thanks Frank for your help, I think I'm further, but still not quite there.
The definition requires me to send the iBandMap as an array, I cannot insert the index of the band I wish to write, because then I'm just passing an integer. So with that said, I decided to combine all my byte arrays (buffers) of data into one array and call Write Raster as follows: byte[] buffers = new byte[(iHeight * iWidth) * 3]; r_buffer.CopyTo(buffers, 0); g_buffer.CopyTo(buffers, r_buffer.Length); b_buffer.CopyTo(buffers, r_buffer.Length * 2); ds_new.WriteRaster(0, 0, iWidth, iHeight, buffers, iWidth, iHeight, 3, iBandMap, 0, 0, 0); But I'm still getting the same exception, so something else must not be quite right. I've tried playing around with the pixelSpace, lineSpace and bandSpace parameters and still no success...any other ideas what I'm still missing? Thanks for any assistance!! Amanda M. Henneke -----Original Message----- From: Frank Warmerdam [mailto:[email protected]] Sent: Friday, July 17, 2009 12:33 PM To: Henneke, Amanda M Cc: [email protected] Subject: Re: [gdal-dev] Creating a new raster and adding data Henneke, Amanda M wrote: ... > This is what I have so far... > > Dataset ds = > Gdal.Open("F:\\Mat_Class\\Alaska\\new_tifs\\class_ak_sheet_8a.tif", > Access.GA_Update); Dataset ds_new = > drv.Create("F:\\Mat_Class\\Alaska\\new_tifs\\class_ak_sheet_8a_test.ti > f", ds.RasterXSize, ds.RasterYSize, 5, DataType.GDT_Byte, new string[] > { }); > > byte[] r_buffer = new byte[iWidth * iHeight]; byte[] g_buffer = new > byte[iWidth * iHeight]; byte[] b_buffer = new byte[iWidth * iHeight]; > > > <get/set values for r_buffer, g_buffer and b_buffer> > > int[] iBandMap = { 1, 2, 3, 4, 5 }; > ds_new.WriteRaster(0, 0, iWidth, iHeight, r_buffer, iWidth, iHeight, > 1, iBandMap, 0, 0, 0); ds_new.WriteRaster(0, 0, iWidth, iHeight, > g_buffer, iWidth, iHeight, 2, iBandMap, 0, 0, 0); > ds_new.WriteRaster(0, 0, iWidth, iHeight, b_buffer, iWidth, iHeight, > 3, iBandMap, 0, 0, 0); Amanda, When I look in gdal/swig/include/csharp/gdal_csharp.i I see this defintion: public CPLErr WriteRaster(int xOff, int yOff, int xSize, int ySize, CSTYPE[] buffer, int buf_xSize, int buf_ySize, int bandCount, int[] bandMap, int pixelSpace, int lineSpace, int bandSpace) I think the problem is that you are passing 1, 2, and 3 as the bandCount value when you are really only passing a buffer (ie. b_buffer) large enough for one band. I suspect you should be passing "1" for bandCount each time, but passing different offets into iBandMap however that is most appopriately done in C#. In C/C++ I could do: int[] iBandMap = { 1, 2, 3, 4, 5 }; ds_new.WriteRaster(0, 0, iWidth, iHeight, r_buffer, iWidth, iHeight, 1, &(iBandMap[0]), 0, 0, 0); ds_new.WriteRaster(0, 0, iWidth, iHeight, g_buffer, iWidth, iHeight, 1, &(iBandMap[1]), 0, 0, 0); ds_new.WriteRaster(0, 0, iWidth, iHeight, b_buffer, iWidth, iHeight, 1, &(iBandMap[2]), 0, 0, 0); I'm not sure how this idiom translates into C#. Good luck, -- ---------------------------------------+-------------------------------- ---------------------------------------+------ I set the clouds in motion - turn up | Frank Warmerdam, [email protected] light and sound - activate the windows | http://pobox.com/~warmerdam and watch the world go round - Rush | Geospatial Programmer for Rent _______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
