avigis

JAVA Raster: Writing to a pixel block

Discussion created by avigis on Dec 30, 2012
Latest reply on Jan 4, 2013 by avigis
Hi,

Can someone please help with the Java code to write values into a pixel block!?

IRasterDataset streamOrder  = rasterWorkSpace.openRasterDataset("streamOrder.tif");
RasterDataset streamOrderRas = (RasterDataset)streamOrder;

RasterBand streamOrderBand = new RasterBand(streamOrderRas.item(0));

IPnt size1 = new DblPnt();
size1.setCoords(streamOrderBand.getWidth(), streamOrderBand.getHeight());

PixelBlock writePixBlock = (PixelBlock)(streamOrderBand.createPixelBlock(size1));
IPnt tlc1 = new DblPnt();
tlc1.setCoords(0, 0);
streamOrderBand.read(tlc1, writePixBlock);

Object vPixels = writePixBlock.getSafeArray(0);


I am not able to proceed further! I cannot cast this vPixels into anything, hence I am not able to access or alter the values inside.

Will changing the safe array and setting it to the pixel block be enough? I also tried IPixelBlock3 but it did not work.

Please can some one show a working example.

Thanks,
Avishek

Outcomes