double precision using IPixelBlock3 and setPixelData

2241
1
Jump to solution
02-27-2013 11:50 PM
PasitheeJupiter
New Contributor
Hi all

I'm trying to to write a double[][] array to a IPixelBlock3 instance using Java. Here is an abstract of my source.
IRasterWorkspace2 workspace = new IRasterWorkspace2Proxy(new RasterWorkspaceFactory().openFromFile(folder, 0)); try {     double[][] data = cache.get(key);      int height = data[0].length;      int width = data.length;       IUnknownCoordinateSystem sr = new UnknownCoordinateSystem();    IPoint origin = new Point();  origin.putCoords(12.5, 12.5);         IRasterDataset rasterDataset = workspace.createRasterDataset(filename, "GRID",           origin, width, height, 25, 25, 1, rstPixelType.PT_DOUBLE, sr,           true);         IRasterBandCollection rasterBands = new IRasterBandCollectionProxy(rasterDataset);      IRasterBand rasterBand;  IRasterProps rasterProps;  rasterBand = rasterBands.item(0);  rasterProps = new IRasterPropsProxy(rasterBand);          rasterProps.setNoDataValue(255);   IRaster raster = rasterDataset.createDefaultRaster();  IPnt blocksize = new Pnt();  blocksize.setCoords(width, height);  IPixelBlock3 pixelblock = new IPixelBlock3Proxy(raster.createPixelBlock      (blocksize));         pixelblock.setPixelData(0, data);    IPnt upperLeft = new Pnt();  upperLeft.setCoords(0, 0);   IRasterEdit rasterEdit = new IRasterEditProxy(raster);  rasterEdit.write(upperLeft, new IPixelBlockProxy(pixelblock));  Cleaner.release(rasterEdit);        } catch (UnknownHostException e) {  throw new IOException(e.getMessage()); } catch (IOException e) {  throw e; }


Using this code, I'm getting the following exception:
Exception in thread "main" AutomationException: 0x80070057 - This spatial reference object cannot be defined from the available information. in '"esri.ProjectedCoordinateSystem"'  at com.esri.arcgis.interop.NativeObjRef.nativeVtblInvokeNative(Native Method)  at com.esri.arcgis.interop.NativeObjRef.a(Unknown Source)  at com.esri.arcgis.interop.NativeObjRef.a(Unknown Source)  at com.esri.arcgis.interop.Dispatch.vtblInvoke(Unknown Source)  at com.esri.arcgis.datasourcesraster.IPixelBlock3Proxy.setPixelData(Unknown Source)  at ILUMOE.writer.RasterWorkspaceWriter.write(RasterWorkspaceWriter.java:94)  at ILUMOE.LoopThroughMatrix.oneTimeStep(LoopThroughMatrix.java:177)  at ILUMOE.ILUMOEControl.main(ILUMOEControl.java:77)


If I change the double[][] to a int[][] and using the PT_UCHAR (8-bit integer) it works.

Does someone has any idea how to store double precision values / points?

Thanks a lot
0 Kudos
1 Solution

Accepted Solutions
PasitheeJupiter
New Contributor
I found a solution as follow:

IRaster raster = rasterDataset.createDefaultRaster();  IPnt blocksize = new DblPnt(); blocksize.setCoords(col_count, row_count);  IPixelBlock3 pixelblock = (IPixelBlock3) raster.createPixelBlock(blocksize); float[][] test = (float[][]) pixelblock.getPixelData(0);  for(int y = 0; y < data.length; y++) {     for(int x = 0; x < data.length; x++) {         test = new Double(data).floatValue();     } }  pixelblock.setPixelData(0, test);  IPnt upperLeft = new DblPnt(); upperLeft.setCoords(0.0, 0.0);  IRasterEdit rasterEdit = new IRasterEditProxy(raster); rasterEdit.write(upperLeft, new IPixelBlockProxy(pixelblock)); Cleaner.release(rasterEdit);


Important is to use DblPnt instead of Pnt and to work with the array given by the IPixelBlock3 as follow
float[][] test = (float[][]) pixelblock.getPixelData(0);

View solution in original post

0 Kudos
1 Reply
PasitheeJupiter
New Contributor
I found a solution as follow:

IRaster raster = rasterDataset.createDefaultRaster();  IPnt blocksize = new DblPnt(); blocksize.setCoords(col_count, row_count);  IPixelBlock3 pixelblock = (IPixelBlock3) raster.createPixelBlock(blocksize); float[][] test = (float[][]) pixelblock.getPixelData(0);  for(int y = 0; y < data.length; y++) {     for(int x = 0; x < data.length; x++) {         test = new Double(data).floatValue();     } }  pixelblock.setPixelData(0, test);  IPnt upperLeft = new DblPnt(); upperLeft.setCoords(0.0, 0.0);  IRasterEdit rasterEdit = new IRasterEditProxy(raster); rasterEdit.write(upperLeft, new IPixelBlockProxy(pixelblock)); Cleaner.release(rasterEdit);


Important is to use DblPnt instead of Pnt and to work with the array given by the IPixelBlock3 as follow
float[][] test = (float[][]) pixelblock.getPixelData(0);
0 Kudos