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.tif", 
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

Reply via email to