public void setBytePixel( int x, int y, byte[] pixel ) { ByteBuffer buf = getByteBuffer(); for ( int band = 0; band < getView().dataInfo.bands; band++ ) { buf.put( calculatePos( x, y, band ), pixel[band] ); } }
public float[] getFloatPixel( int x, int y, float[] result ) { if ( result == null || result.length < getView().dataInfo.bands ) { result = new float[getView().dataInfo.bands]; } for ( int band = 0; band < getView().dataInfo.bands; band++ ) { result[band] = getFloatSample( x, y, band ); } return result; }
public void setSubset( int x0, int y0, int width, int height, RasterData sourceRaster ) { setSubset( x0, y0, width, height, sourceRaster, 0, 0 ); }
public ByteBufferRasterData createCompatibleRasterData() { // just use the view on the data return createCompatibleRasterData( getView() ); }
RasterDataInfo view = raster.getDataInfo(); int width = raster.getColumns(); int height = raster.getRows(); DataType type = raster.getDataType(); for ( int y = 0; y < height; y++ ) { for ( int x = 0; x < width; x++ ) { raster.getPixel( x, y, buf ); outputRaster.setDataElements( x, y, mapToRGB( output, buf, view.bandInfo ) ); for ( int y = 0; y < height; y++ ) { for ( int x = 0; x < width; x++ ) { raster.getDoublePixel( x, y, dbuf ); outputRaster.setDataElements( x, y, dbuf ); for ( int y = 0; y < height; y++ ) { for ( int x = 0; x < width; x++ ) { raster.getIntPixel( x, y, ibuf ); outputRaster.setDataElements( x, y, ibuf ); SampleModel fm = new BandedSampleModel( DataBuffer.TYPE_FLOAT, raster.getColumns(), raster.getRows(), bands ); DataBuffer db = new RawDataBufferFloat( raster.getByteBuffer(), f.get( 0 ), raster.getBytebufferDomain(), raster.getView() ); for ( int y = 0; y < height; y++ ) { for ( int x = 0; x < width; x++ ) { raster.getShortPixel( x, y, sbuf );
public byte[] getBytes( int x, int y, int width, int height, int band, byte[] result ) { checkBoundsEx( x, y, width, height ); if ( result == null || result.length < ( width * height ) ) { result = new byte[width * height]; } for ( int h = 0; h < height; h++ ) { for ( int w = 0; w < width; w++ ) { int pos = calculatePos( x + w, y + h, band ); int rOffset = ( 2 * h ) + w; if ( pos == -1 ) {// the position is outside the databuffer. result[rOffset] = getView().dataInfo.noDataPixel[getView().getBandOffset( band )]; } else { result[rOffset] = getByteBuffer().get( pos ); } } } return result; }
public void setDoubles( int x, int y, int width, int height, int band, double[] values ) { if ( values != null && values.length >= ( width * height ) ) { ByteBuffer buf = getByteBuffer(); for ( int h = 0; h < height; h++ ) { for ( int w = 0; w < width; w++ ) { buf.putDouble( calculatePos( x + w, y + h, band ), values[( 2 * h ) + w] ); } } } }
public ByteBufferRasterData getSubset( RasterRect sampleDomain, BandType[] bands ) { int newOrigx = min( getView().x + sampleDomain.x, getOriginalWidth() ); int newOrigy = min( getView().y + sampleDomain.y, getOriginalHeight() ); ByteBufferRasterData result = createCompatibleRasterData( new DataView( newOrigx, newOrigy, newWidth, newHeight, createRasterDataInfo( bands ), dataInfo ) ); result.info = info; result.dataAccess.setByteBuffer( getByteBuffer().asReadOnlyBuffer(), dataAccess.getBytebufferDomain() );
public void setSubset( int dstX, int dstY, int width, int height, RasterData srcRaster, int srcX, int srcY ) { // clamp to maximum possible size // int subWidth = min( this.rasterWidth - dstX, width, srcRaster.getWidth() ); // int subHeight = min( this.rasterHeight - dstY, height, srcRaster.getHeight() ); int subWidth = clampSize( getColumns(), dstX, srcRaster.getColumns(), srcX, width ); int subHeight = clampSize( getRows(), dstY, srcRaster.getRows(), srcY, height ); if ( subHeight <= 0 || subWidth <= 0 ) { return; } byte[] tmp = new byte[dataInfo.dataSize]; for ( int y = 0; y < subHeight; ++y ) { for ( int x = 0; x < subWidth; ++x ) { for ( int band = 0; band < this.getView().dataInfo.bands; band++ ) { srcRaster.getSample( x + srcX, y + srcY, band, tmp ); setSample( dstX + x, dstY + y, band, tmp ); } } } }
public byte[] getPixel( int x, int y, byte[] result ) { // operates on the getView(). int numBands = getView().dataInfo.bands; // datasize should be equal between original data and the view int sampleSize = getView().dataInfo.dataSize; if ( result == null || result.length < ( numBands * sampleSize ) ) { result = new byte[numBands * sampleSize]; } // null pixel if ( 0 > x || x >= getOriginalWidth() || 0 > y || y >= getOriginalHeight() ) { System.arraycopy( getView().dataInfo.noDataPixel, 0, result, 0, result.length ); return result; } // copy per band on the getView(). for ( int b = 0; b < numBands; b++ ) { int pos = calculatePos( x, y, b ); if ( pos == -1 ) {// the position is outside the databuffer. System.arraycopy( getView().dataInfo.noDataPixel, b * sampleSize, result, b * sampleSize, sampleSize ); } else { ByteBuffer buf = getByteBuffer(); buf.position( pos ); buf.get( result, b * sampleSize, sampleSize ); } } return result; }
newKernel.fillWithNoData(); newKernel.setSubset( 0, 0, size, size, subset, 0, 0 ); float centerValue = newKernel.getFloatSample( size2, size2, 0 ); for ( int ky = 0; ky < size; ky++ ) { for ( int kx = 0; kx < size; kx++ ) { float d = newKernel.getFloatSample( kx, ky, 0 ); if ( Math.abs( centerValue - d ) > minDiff ) { newKernel.setFloatSample( kx, ky, 0, noData ); int sizeSquared = size * size; while ( stdev < kStdevCNT[0] * stdevCorr && t++ < ( sizeSquared ) ) { newKernel.setFloatSample( (int) kStdevCNT[3], (int) kStdevCNT[2], 0, noData ); for ( int ky = 0; ky < size; ky++ ) { for ( int kx = 0; kx < size; kx++ ) { float value = newKernel.getFloatSample( kx, ky, 0 );
@Override public RasterData asReadOnly() { ByteBufferRasterData copy = createCompatibleEmptyRasterData(); copy.info = info; // this instantiation ensures a readonly buffer. copy.setByteBuffer( this.getByteBuffer().asReadOnlyBuffer(), null ); return copy; }
public void setSubset( int dstX, int dstY, int width, int height, int dstBand, RasterData srcRaster, int srcBand, int srcX, int srcY ) { // clamp to maximum possible size // int subWidth = min( this.rasterWidth - dstX, width, srcRaster.getWidth() ); // int subHeight = min( this.rasterHeight - dstY, height, srcRaster.getHeight() ); int subWidth = clampSize( getColumns(), dstX, srcRaster.getColumns(), srcX, width ); int subHeight = clampSize( getRows(), dstY, srcRaster.getRows(), srcY, height ); if ( subHeight <= 0 || subWidth <= 0 ) { return; } byte[] tmp = new byte[dataInfo.dataSize]; for ( int y = 0; y < subHeight; y++ ) { for ( int x = 0; x < subWidth; x++ ) { srcRaster.getSample( x + srcX, y + srcY, srcBand, tmp ); setSample( dstX + x, dstY + y, dstBand, tmp ); } } }
public ByteBufferRasterData getSubset( RasterRect sampleDomain ) { // return this.getSubset( env.x, env.y, env.width, env.height ); // return createCompatibleRasterData( sampleDomain ); ByteBufferRasterData result = createCompatibleRasterData( new DataView( getView().x + sampleDomain.x, getView().y + sampleDomain.y, sampleDomain.width, sampleDomain.height, dataInfo ) ); if ( dataAccess.hasDataBuffer() && dataAccess.getReader() == null ) { // the data was loaded, but no reader was available, we need a copy of the data. result.dataAccess.setByteBuffer( getByteBuffer().asReadOnlyBuffer(), dataAccess.getBytebufferDomain() ); // result.dataAccess.setByteBuffer( getByteBuffer().asReadOnlyBuffer(), view ); // result.data = this.data.asReadOnlyBuffer(); } // result.dataAccess.setByteBuffer( getByteBuffer().asReadOnlyBuffer(), view ); // result.data = this.data.asReadOnlyBuffer(); return result; }
fileData.setSubset( 0, 0, newDataPosition.width, newDataPosition.height, subRaster.getRasterData() ); FileLock lock = fileChannel.lock( position, position + bytesPerTile, false ); fileChannel.position( position ); ByteBuffer buffer = fileData.getByteBuffer();
public ByteBufferRasterData createCompatibleRasterData( BandType[] bands ) { // create a new view from the given bands return createCompatibleRasterData( new DataView( getView(), createRasterDataInfo( bands ), dataInfo ) ); }
@Override public BufferResult read( RasterRect rect, ByteBuffer buffer ) throws IOException { // rb: not very optimized yet.. BufferedReader reader = new BufferedReader( new FileReader( this.file ) ); ByteBufferRasterData grid = readASCIIGrid( reader, null ); reader.close(); ByteBufferRasterData subset = grid.getSubset( rect ); return new BufferResult( rect, subset.getByteBuffer() ); }
/** * @param reader * @param nOpts * @throws IOException */ private SimpleRaster createSimpleRaster( BufferedReader reader, RasterIOOptions nOpts ) throws IOException { ByteBufferRasterData data = readASCIIGrid( reader, nOpts ); ByteBuffer byteBuffer = data.getByteBuffer(); data = RasterDataFactory.createRasterData( width, height, data.getDataInfo(), geoReference, byteBuffer, true, FileUtils.getFilename( this.file ), nOpts ); SimpleRaster simpleRaster = new SimpleRaster( data, this.envelope, geoReference, null ); return simpleRaster; }
private ByteBufferRasterData readData( int column, int row ) throws IOException { synchronized ( LOCK ) { ByteBuffer buffer = tileData.getByteBuffer(); buffer.clear(); long position = calcFilePosition( column, row ); // transfer the data from the blob FileChannel channel = getReadChannel(); channel.position( position ); channel.read( buffer ); closeReadStream(); buffer.rewind(); return tileData; // return new PixelInterleavedRasterData( new RasterRect( 0, 0, tileRasterWidth, tileRasterHeight ), // tileRasterWidth, tileRasterHeight, this.dataInfo ); } }
RasterReader rasterReader = ( (ByteBufferRasterData) simpleRaster.getRasterData() ).getReader(); File file = rasterReader.file(); File outputLocation = getOutputLocation( file, outLoc, outputFormat, tiles.size() == 1 ); File outFile = null; ByteBufferRasterData data = (ByteBufferRasterData) tile.getRasterData(); RasterReader origReader = data.getReader(); final String tileName = origReader.getDataLocationId(); if ( tiles.size() == 1 ) {