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; }
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)
Solved! Go to Solution.
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);
float[][] test = (float[][]) pixelblock.getPixelData(0);
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);
float[][] test = (float[][]) pixelblock.getPixelData(0);