@Test @Category(UnitTest.class) public void toRasterDouble() throws IOException { Raster raster = numberedDouble.toRaster(); compareRaster(numberedDouble, raster); }
final public Raster toRaster() { WritableRaster raster = RasterUtils.createEmptyRaster(width, height, bands, datatype); ByteBuffer rasterBuffer = ByteBuffer.wrap(data); rasterBuffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < HEADER_LEN; i++) { rasterBuffer.get(); } int databytes = data.length - HEADER_LEN; switch (datatype) { case DataBuffer.TYPE_BYTE: byte[] bytedata = new byte[databytes]; rasterBuffer.get(bytedata); raster.setDataElements(0, 0, width, height, bytedata); break; case DataBuffer.TYPE_FLOAT: FloatBuffer floatbuff = rasterBuffer.asFloatBuffer(); float[] floatdata = new float[databytes / bytesPerPixel()]; floatbuff.get(floatdata); raster.setDataElements(0, 0, width, height, floatdata); break; case DataBuffer.TYPE_DOUBLE: DoubleBuffer doublebuff = rasterBuffer.asDoubleBuffer(); double[] doubledata = new double[databytes / bytesPerPixel()]; doublebuff.get(doubledata); raster.setDataElements(0, 0, width, height, doubledata); break; case DataBuffer.TYPE_INT: IntBuffer intbuff = rasterBuffer.asIntBuffer(); int[] intdata = new int[databytes / bytesPerPixel()]; intbuff.get(intdata); raster.setDataElements(0, 0, width, height, intdata); break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: ShortBuffer shortbuff = rasterBuffer.asShortBuffer(); short[] shortdata = new short[databytes / bytesPerPixel()]; shortbuff.get(shortdata); raster.setDataElements(0, 0, width, height, shortdata); break; default: throw new RasterWritableException("Error trying to read raster. Bad raster data type"); } return raster; }
MrGeoRaster implements Serializable { final public Raster toRaster() { WritableRaster raster = RasterUtils.createEmptyRaster(width, height, bands, datatype); ByteBuffer rasterBuffer = ByteBuffer.wrap(data); rasterBuffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < HEADER_LEN; i++) { rasterBuffer.get(); } int databytes = data.length - HEADER_LEN; switch (datatype) { case DataBuffer.TYPE_BYTE: byte[] bytedata = new byte[databytes]; rasterBuffer.get(bytedata); raster.setDataElements(0, 0, width, height, bytedata); break; case DataBuffer.TYPE_FLOAT: FloatBuffer floatbuff = rasterBuffer.asFloatBuffer(); float[] floatdata = new float[databytes / bytesPerPixel()]; floatbuff.get(floatdata); raster.setDataElements(0, 0, width, height, floatdata); break; case DataBuffer.TYPE_DOUBLE: DoubleBuffer doublebuff = rasterBuffer.asDoubleBuffer(); double[] doubledata = new double[databytes / bytesPerPixel()]; doublebuff.get(doubledata); raster.setDataElements(0, 0, width, height, doubledata); break; case DataBuffer.TYPE_INT: IntBuffer intbuff = rasterBuffer.asIntBuffer(); int[] intdata = new int[databytes / bytesPerPixel()]; intbuff.get(intdata); raster.setDataElements(0, 0, width, height, intdata); break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: ShortBuffer shortbuff = rasterBuffer.asShortBuffer(); short[] shortdata = new short[databytes / bytesPerPixel()]; shortbuff.get(shortdata); raster.setDataElements(0, 0, width, height, shortdata); break; default: throw new RasterWritableException("Error trying to read raster. Bad raster data type"); } return raster; } }
MrGeoRaster implements Serializable { final public Raster toRaster() { WritableRaster raster = RasterUtils.createEmptyRaster(width, height, bands, datatype); ByteBuffer rasterBuffer = ByteBuffer.wrap(data); rasterBuffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < HEADER_LEN; i++) { rasterBuffer.get(); } int databytes = data.length - HEADER_LEN; switch (datatype) { case DataBuffer.TYPE_BYTE: byte[] bytedata = new byte[databytes]; rasterBuffer.get(bytedata); raster.setDataElements(0, 0, width, height, bytedata); break; case DataBuffer.TYPE_FLOAT: FloatBuffer floatbuff = rasterBuffer.asFloatBuffer(); float[] floatdata = new float[databytes / bytesPerPixel()]; floatbuff.get(floatdata); raster.setDataElements(0, 0, width, height, floatdata); break; case DataBuffer.TYPE_DOUBLE: DoubleBuffer doublebuff = rasterBuffer.asDoubleBuffer(); double[] doubledata = new double[databytes / bytesPerPixel()]; doublebuff.get(doubledata); raster.setDataElements(0, 0, width, height, doubledata); break; case DataBuffer.TYPE_INT: IntBuffer intbuff = rasterBuffer.asIntBuffer(); int[] intdata = new int[databytes / bytesPerPixel()]; intbuff.get(intdata); raster.setDataElements(0, 0, width, height, intdata); break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: ShortBuffer shortbuff = rasterBuffer.asShortBuffer(); short[] shortdata = new short[databytes / bytesPerPixel()]; shortbuff.get(shortdata); raster.setDataElements(0, 0, width, height, shortdata); break; default: throw new RasterWritableException("Error trying to read raster. Bad raster data type"); } return raster; } MrGeoRaster(int width, int height, int bands, int datatype, byte[] data, int dataoffset); }
MrGeoRaster implements Serializable { final public Raster toRaster() { WritableRaster raster = RasterUtils.createEmptyRaster(width, height, bands, datatype); ByteBuffer rasterBuffer = ByteBuffer.wrap(data); rasterBuffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < HEADER_LEN; i++) { rasterBuffer.get(); } int databytes = data.length - HEADER_LEN; switch (datatype) { case DataBuffer.TYPE_BYTE: byte[] bytedata = new byte[databytes]; rasterBuffer.get(bytedata); raster.setDataElements(0, 0, width, height, bytedata); break; case DataBuffer.TYPE_FLOAT: FloatBuffer floatbuff = rasterBuffer.asFloatBuffer(); float[] floatdata = new float[databytes / bytesPerPixel()]; floatbuff.get(floatdata); raster.setDataElements(0, 0, width, height, floatdata); break; case DataBuffer.TYPE_DOUBLE: DoubleBuffer doublebuff = rasterBuffer.asDoubleBuffer(); double[] doubledata = new double[databytes / bytesPerPixel()]; doublebuff.get(doubledata); raster.setDataElements(0, 0, width, height, doubledata); break; case DataBuffer.TYPE_INT: IntBuffer intbuff = rasterBuffer.asIntBuffer(); int[] intdata = new int[databytes / bytesPerPixel()]; intbuff.get(intdata); raster.setDataElements(0, 0, width, height, intdata); break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: ShortBuffer shortbuff = rasterBuffer.asShortBuffer(); short[] shortdata = new short[databytes / bytesPerPixel()]; shortbuff.get(shortdata); raster.setDataElements(0, 0, width, height, shortdata); break; default: throw new RasterWritableException("Error trying to read raster. Bad raster data type"); } return raster; } MrGeoRaster(int width, int height, int bands, int datatype, byte[] data, int dataoffset); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype, double nodata); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype, double[] nodatas); static MrGeoRaster createRaster(int width, int height, int bands, int datatype, byte[] data, int dataOffset); static MrGeoRaster fromRaster(Raster raster); static MrGeoRaster fromDataset(Dataset dataset); static MrGeoRaster fromDataset(Dataset dataset, int x, int y, int width,
    int height); final MrGeoRaster createCompatibleRaster(int width, int height); final MrGeoRaster createCompatibleEmptyRaster(int width, int height, double nodata); final MrGeoRaster createCompatibleEmptyRaster(int width, int height, double[] nodata); final int width(); final int height(); final int bands(); final int datatype(); final int dataoffset(); final int datasize(); final int datalength(); final MrGeoRaster clip(int x, int y, int width, int height); final MrGeoRaster clip(int x, int y, int width, int height, int band); final void copyFrom(int srcx, int srcy, int width, int height, MrGeoRaster src, int dstx, int dsty); final void copyFrom(int srcx, int srcy, int srcBand, int width, int height, MrGeoRaster src,
    int dstx, int dsty, int dstBand); final void fill(double value); final void fill(double[] values); final void fill(int band, double value); MrGeoRaster scale(int dstWidth,
    int dstHeight, boolean interpolate, double[] nodatas); final MrGeoRaster reduce(int xfactor, int yfactor, Aggregator aggregator, double[] nodatas); final void mosaic(MrGeoRaster other, double[] nodata); final Dataset toDataset(); final Dataset toDiskBasedDataset(Bounds bounds, double[] nodatas,
    int xoffset, int yoffset, int outWidth, int outHeight); final Dataset toDataset(Bounds bounds, double[] nodatas); void copyToDataset(Dataset ds, int dsWidth, int dsHeight, Bounds fullBounds, Bounds bounds,
    int tilesize, int zoomlevel, int gdaltype); final Raster toRaster(); abstract byte getPixelByte(int x, int y, int band); abstract short getPixelShort(int x, int y, int band); abstract short getPixeUShort(int x, int y, int band); abstract int getPixelInt(int x, int y, int band); abstract float getPixelFloat(int x, int y, int band); abstract double getPixelDouble(int x, int y, int band); abstract void setPixel(int x, int y, int band, byte pixel); abstract void setPixel(int x, int y, int band, short pixel); abstract void setPixel(int x, int y, int band, int pixel); abstract void setPixel(int x, int y, int band, float pixel); abstract void setPixel(int x, int y, int band, double pixel); abstract int bytesPerPixel(); }
MrGeoRaster implements Serializable { final public Raster toRaster() { WritableRaster raster = RasterUtils.createEmptyRaster(width, height, bands, datatype); ByteBuffer rasterBuffer = ByteBuffer.wrap(data); rasterBuffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < HEADER_LEN; i++) { rasterBuffer.get(); } int databytes = data.length - HEADER_LEN; switch (datatype) { case DataBuffer.TYPE_BYTE: byte[] bytedata = new byte[databytes]; rasterBuffer.get(bytedata); raster.setDataElements(0, 0, width, height, bytedata); break; case DataBuffer.TYPE_FLOAT: FloatBuffer floatbuff = rasterBuffer.asFloatBuffer(); float[] floatdata = new float[databytes / bytesPerPixel()]; floatbuff.get(floatdata); raster.setDataElements(0, 0, width, height, floatdata); break; case DataBuffer.TYPE_DOUBLE: DoubleBuffer doublebuff = rasterBuffer.asDoubleBuffer(); double[] doubledata = new double[databytes / bytesPerPixel()]; doublebuff.get(doubledata); raster.setDataElements(0, 0, width, height, doubledata); break; case DataBuffer.TYPE_INT: IntBuffer intbuff = rasterBuffer.asIntBuffer(); int[] intdata = new int[databytes / bytesPerPixel()]; intbuff.get(intdata); raster.setDataElements(0, 0, width, height, intdata); break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: ShortBuffer shortbuff = rasterBuffer.asShortBuffer(); short[] shortdata = new short[databytes / bytesPerPixel()]; shortbuff.get(shortdata); raster.setDataElements(0, 0, width, height, shortdata); break; default: throw new RasterWritableException("Error trying to read raster. Bad raster data type"); } return raster; } MrGeoRaster(int width, int height, int bands, int datatype, byte[] data, int dataoffset); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype, double nodata); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype, double[] nodatas); static MrGeoRaster createRaster(int width, int height, int bands, int datatype, byte[] data, int dataOffset); static MrGeoRaster fromRaster(Raster raster); static MrGeoRaster fromDataset(Dataset dataset); static MrGeoRaster fromDataset(Dataset dataset, int x, int y, int width,
    int height); final MrGeoRaster createCompatibleRaster(int width, int height); final MrGeoRaster createCompatibleEmptyRaster(int width, int height, double nodata); final MrGeoRaster createCompatibleEmptyRaster(int width, int height, double[] nodata); final int width(); final int height(); final int bands(); final int datatype(); final int dataoffset(); final int datasize(); final int datalength(); final MrGeoRaster clip(int x, int y, int width, int height); final MrGeoRaster clip(int x, int y, int width, int height, int band); final void copyFrom(int srcx, int srcy, int width, int height, MrGeoRaster src, int dstx, int dsty); final void copyFrom(int srcx, int srcy, int srcBand, int width, int height, MrGeoRaster src,
    int dstx, int dsty, int dstBand); final void fill(double value); final void fill(double[] values); final void fill(int band, double value); MrGeoRaster scale(int dstWidth,
    int dstHeight, boolean interpolate, double[] nodatas); final MrGeoRaster reduce(int xfactor, int yfactor, Aggregator aggregator, double[] nodatas); final void mosaic(MrGeoRaster other, double[] nodata); final Dataset toDataset(); final Dataset toDiskBasedDataset(Bounds bounds, double[] nodatas,
    int xoffset, int yoffset, int outWidth, int outHeight); final Dataset toDataset(Bounds bounds, double[] nodatas); void copyToDataset(Dataset ds, int dsWidth, int dsHeight, Bounds fullBounds, Bounds bounds,
    int tilesize, int zoomlevel, int gdaltype); final Raster toRaster(); abstract byte getPixelByte(int x, int y, int band); abstract short getPixelShort(int x, int y, int band); abstract short getPixeUShort(int x, int y, int band); abstract int getPixelInt(int x, int y, int band); abstract float getPixelFloat(int x, int y, int band); abstract double getPixelDouble(int x, int y, int band); abstract void setPixel(int x, int y, int band, byte pixel); abstract void setPixel(int x, int y, int band, short pixel); abstract void setPixel(int x, int y, int band, int pixel); abstract void setPixel(int x, int y, int band, float pixel); abstract void setPixel(int x, int y, int band, double pixel); abstract int bytesPerPixel();  }