org.deegree.coverage.raster.data.nio
Class ByteBufferRasterData

java.lang.Object
  extended by org.deegree.coverage.raster.data.nio.ByteBufferRasterData
All Implemented Interfaces:
RasterData
Direct Known Subclasses:
BandInterleavedRasterData, LineInterleavedRasterData, PixelInterleavedRasterData

public abstract class ByteBufferRasterData
extends Object
implements RasterData

This abstract class implements the RasterData interface for ByteBuffer based raster.

It is based on java.nio.ByteBuffer and implements common get- and set-operations on the data. The different InterleaveTypes are implemented by additional subclasses.

get- and set-operations are implemented naive and access all data sample-wise. For efficiency subclasses should overwrite methods that access more than one sample and leverage the knowledge of the internal storage format (interleaving).

TODO: Only implements access to byte and float data at the moment. Copy float methods for other data types and change 'Float/float' to short, int, long or double. These types are supported by ByteBuffer and the according methods only differ in the name of the type (eg. getFloat, getInt, getDouble,...). Opposed to the methods for bytes, which lack the type in the method names (eg. only get()).

Also this implementation is able to store a sub-view on another ByteBufferRasterData, resp. ByteBuffer. With this feature you are able to create subsets without copying the data. Though the current deegree SimpleRaster implementation makes no use of it.

Version:
$Revision: 31644 $, $Date: 2011-08-24 22:27:43 +0200 (Wed, 24 Aug 2011) $
Author:
Oliver Tonnhofer, last edited by: $Author: mschneider $

Field Summary
protected  BufferAccess dataAccess
          Buffer access holds a reference to the reader so not all data should be in memory
protected  RasterDataInfo dataInfo
          the raster data info of the original data, not the view.
 String info
          information on this raster data
protected  int rasterHeight
          the height of the raster
protected  int rasterWidth
          the width of the raster
 
Fields inherited from interface org.deegree.coverage.raster.data.RasterData
TYPE_BYTE_RGB, TYPE_BYTE_RGBA
 
Constructor Summary
protected ByteBufferRasterData(DataView view, int rasterWidth, int rasterHeight, RasterReader reader, RasterDataInfo originalDataInfo)
          Creates a new ByteBufferRasterData instance.
protected ByteBufferRasterData(DataView view, int rasterWidth, int rasterHeight, RasterReader reader, RasterDataInfo originalDataInfo, boolean init)
          Creates a new ByteBufferRasterData instance.
 
Method Summary
 RasterData asReadOnly()
          Return a read-only version of this RasterData.
 int calculatePos(int x, int y)
          Calculates the position of a pixel in the ByteBuffer.
 int calculatePos(int x, int y, int bandOfView)
          Calculates the position of a sample in the ByteBuffer.
 int calculateViewPos(int x, int y)
          Calculates the position of a pixel in a view (FloatBuffer, etc.) of the ByteBuffer.
 int calculateViewPos(int x, int y, int band)
          Calculates the position of a sample in a view (FloatBuffer, etc.) of the ByteBuffer.
protected  boolean checkBounds(int x, int y, int width, int height)
          Checks whether a given rect is inside the raster.
protected  void checkBoundsEx(int x, int y, int width, int height)
          Checks whether a given rect is inside the raster, throws an exception if outside.
protected static int clampSize(int dstSize, int dstOrdinate, int srcSize, int srcOrdinate, int copySize)
          Clamp to the minimal size of the given values.
protected abstract  ByteBufferRasterData createCompatibleEmptyRasterData()
           
 ByteBufferRasterData createCompatibleRasterData()
          Returns a new RasterData with the same size, bands, DataType and InterleaveType
 ByteBufferRasterData createCompatibleRasterData(BandType[] bands)
          Returns a new RasterData with the same size, DataType and InterleaveType
protected abstract  ByteBufferRasterData createCompatibleRasterData(DataView view)
          Implementation should create a view of this raster data.
 ByteBufferRasterData createCompatibleRasterData(int width, int height)
          Returns a new RasterData with the same DataType and InterleaveType and all bands
 ByteBufferRasterData createCompatibleRasterData(RasterRect env)
          Returns a view as a new RasterData with the same DataType and InterleaveType but valid only for the given rect.
 RasterData createCompatibleRasterData(RasterRect sampleDomain, BandType[] bands)
          Returns a new RasterData with the same DataType and InterleaveType
protected  RasterDataInfo createRasterDataInfo(BandType[] bands)
          Create the raster data info object for the given bands, if empty or null the current dataInfo will be used.
 void dispose()
          Try to dispose all allocated memory of this data object.
 void fillWithNoData()
          Fills the entire buffer with no data values.
 int getBands()
          Returns the number of bands of the raster
abstract  int getBandStride()
          Returns the byte offset to the next sample of the same pixel.
 ByteBuffer getByteBuffer()
           
 RasterRect getBytebufferDomain()
           
 byte[] getBytePixel(int x, int y, byte[] result)
          Returns a byte array with all sample values from coordinate x/y.
 byte[] getBytes(int x, int y, int width, int height, int band, byte[] result)
          Gets values from the specified rectangle and band.
 byte getByteSample(int x, int y, int band)
          Returns a byte sample from coordinate x/y and selected band.
 int getColumns()
          Returns the width of the raster
 RasterDataInfo getDataInfo()
          Returns an encapsulation of all available information of this raster data.
 DataType getDataType()
          Returns the data type of the raster.
 double[] getDoublePixel(int x, int y, double[] result)
          Returns a double array with all sample values from coordinate x/y.
 double[] getDoubles(int x, int y, int width, int height, int band, double[] result)
          Gets values from the specified rectangle and band.
 double getDoubleSample(int x, int y, int band)
          Returns a double sample from coordinate x/y and selected band.
 float[] getFloatPixel(int x, int y, float[] result)
          Returns a float array with all sample values from coordinate x/y.
 float[] getFloats(int x, int y, int width, int height, int band, float[] result)
          Gets values from the specified rectangle and band.
 float getFloatSample(int x, int y, int band)
          Returns a float sample from coordinate x/y and selected band.
 int[] getIntPixel(int x, int y, int[] result)
          Returns an integer array with all sample values from coordinate x/y.
 int[] getInts(int x, int y, int width, int height, int band, int[] result)
          Gets values from the specified rectangle and band.
 int getIntSample(int x, int y, int band)
          Returns an integer sample from coordinate x/y and selected band.
abstract  int getLineStride()
          Returns the byte offset to the next row (same column, same sample)
 byte[] getNullPixel(byte[] result)
          Returns the no data values for this raster, or the view of this rasters bands.
 RasterDataInfo getOriginalDataInfo()
           
 int getOriginalHeight()
           
 int getOriginalWidth()
           
 byte[] getPixel(int x, int y, byte[] result)
          Returns a pixel as byte array, regardless of the DataType. i.e. a FLOAT DataType results in a four byte array.
abstract  int getPixelStride()
          Retruns the byte offset to the next pixel.
 RasterReader getReader()
           
 int getRequiredBufferSize()
          Returns the needed size of the ByteBuffer in bytes.
 int getRows()
          Returns the height of the raster
 byte[] getSample(int x, int y, int band, byte[] result)
          Returns a sample as byte array, regardless of the DataType. i.e. a FLOAT DataType results in a four byte array
 short[] getShortPixel(int x, int y, short[] result)
          Returns a short array with all sample values from coordinate x/y.
 short[] getShorts(int x, int y, int width, int height, int band, short[] result)
          Gets values from the specified rectangle and band.
 short getShortSample(int x, int y, int band)
          Returns a short sample from coordinate x/y and selected band.
 ByteBufferRasterData getSubset(RasterRect sampleDomain)
          Returns new RasterData object for the specified rectangle.
 ByteBufferRasterData getSubset(RasterRect sampleDomain, BandType[] bands)
          Returns new single-band RasterData object for the specified rectangle.
 DataView getView()
           
protected  void initByteBuffer()
          Initialize the internal ByteBuffer
protected static int min(int... sizes)
          Returns the smallest value of all ints.
 void setByteBuffer(ByteBuffer buf, DataView dataRect)
          Use the given bytebuffer as a data source.
 void setBytePixel(int x, int y, byte[] pixel)
          Sets a single pixel with byte values for each sample.
 void setBytes(int x, int y, int width, int height, int band, byte[] values)
          Sets values from the array to the specified rectangle and band.
 void setByteSample(int x, int y, int band, byte value)
          Sets a single byte sample on coordinate x/y and selected band.
 void setDoublePixel(int x, int y, double[] pixel)
          Sets a single pixel with double values for each sample.
 void setDoubles(int x, int y, int width, int height, int band, double[] values)
          Sets values from the array to the specified rectangle and band.
 void setDoubleSample(int x, int y, int band, double value)
          Sets a single double sample on coordinate x/y and selected band.
 void setFloatPixel(int x, int y, float[] pixel)
          Sets a single pixel with float values for each sample.
 void setFloats(int x, int y, int width, int height, int band, float[] values)
          Sets values from the array to the specified rectangle and band.
 void setFloatSample(int x, int y, int band, float value)
          Sets a single float sample on coordinate x/y and selected band.
 void setIntPixel(int x, int y, int[] pixel)
          Sets a single pixel with integer values for each sample.
 void setInts(int x, int y, int width, int height, int band, int[] values)
          Sets values from the array to the specified rectangle and band.
 void setIntSample(int x, int y, int band, int value)
          Sets a single integer sample on coordinate x/y and selected band.
 void setNoDataValue(byte[] values)
          Sets the no data values for this raster
 void setPixel(int x, int y, byte[] result)
          Sets a pixel with data from a byte array, regardless of the DataType. i.e. a float sample must be packed as a four byte array.
 void setSample(int x, int y, int band, byte[] value)
          Sets a sample with data from a byte array, regardless of the DataType. i.e. a float must be packed as a four byte array
 void setShortPixel(int x, int y, short[] pixel)
          Sets a single pixel with short values for each sample.
 void setShorts(int x, int y, int width, int height, int band, short[] values)
          Sets values from the array to the specified rectangle and band.
 void setShortSample(int x, int y, int band, short value)
          Sets a single short sample on coordinate x/y and selected band.
 void setSubset(int x0, int y0, int width, int height, int dstBand, RasterData sourceRaster, int srcBand)
          Sets a single band of the raster with values from one band of the sourceRaster.
 void setSubset(int dstX, int dstY, int width, int height, int dstBand, RasterData srcRaster, int srcBand, int srcX, int srcY)
          Sets a single band of the raster with values from one band of the sourceRaster.
 void setSubset(int x0, int y0, int width, int height, RasterData sourceRaster)
          Sets the raster with values from sourceRaster.
 void setSubset(int dstX, int dstY, int width, int height, RasterData srcRaster, int srcX, int srcY)
          Sets the raster with values from sourceRaster.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.deegree.coverage.raster.data.RasterData
createCompatibleWritableRasterData
 

Field Detail

rasterWidth

protected int rasterWidth
the width of the raster


rasterHeight

protected int rasterHeight
the height of the raster


dataInfo

protected RasterDataInfo dataInfo
the raster data info of the original data, not the view.


dataAccess

protected BufferAccess dataAccess
Buffer access holds a reference to the reader so not all data should be in memory


info

public String info
information on this raster data

Constructor Detail

ByteBufferRasterData

protected ByteBufferRasterData(DataView view,
                               int rasterWidth,
                               int rasterHeight,
                               RasterReader reader,
                               RasterDataInfo originalDataInfo,
                               boolean init)
Creates a new ByteBufferRasterData instance.

Parameters:
view - the raster rectangle defining the sample domain of this raster data.
rasterWidth - width of the raster data
rasterHeight - height of the raster data
reader - to be used to read the data from a location.
originalDataInfo - containing information about this raster data object
init - true if the ByteBuffer should be initialized

ByteBufferRasterData

protected ByteBufferRasterData(DataView view,
                               int rasterWidth,
                               int rasterHeight,
                               RasterReader reader,
                               RasterDataInfo originalDataInfo)
Creates a new ByteBufferRasterData instance.

Parameters:
view - the raster rectangle defining the sample domain of this raster data.
rasterWidth - width of the raster data
rasterHeight - height of the raster data
reader - to be used to read the data.
originalDataInfo - containing information about this raster data object
Method Detail

createCompatibleRasterData

protected abstract ByteBufferRasterData createCompatibleRasterData(DataView view)
Implementation should create a view of this raster data.

Parameters:
view - the new view on this data
Returns:
a view or new raster data object, backed by a ByteBuffer

createCompatibleEmptyRasterData

protected abstract ByteBufferRasterData createCompatibleEmptyRasterData()
Returns:
ByteBufferRasterData with unset data

getPixelStride

public abstract int getPixelStride()
Retruns the byte offset to the next pixel.

Returns:
byte offset to next pixel

getBandStride

public abstract int getBandStride()
Returns the byte offset to the next sample of the same pixel.

Returns:
byte offset to sample in the next band (same pixel)

getLineStride

public abstract int getLineStride()
Returns the byte offset to the next row (same column, same sample)

Returns:
byte offset to next row (same column, same sample)

fillWithNoData

public void fillWithNoData()
Fills the entire buffer with no data values. Note this operation is only possible on writable buffers.


getView

public DataView getView()
Returns:
the view on the data

initByteBuffer

protected void initByteBuffer()
Initialize the internal ByteBuffer


setByteBuffer

public void setByteBuffer(ByteBuffer buf,
                          DataView dataRect)
Use the given bytebuffer as a data source. This method should be handled with much care.

Parameters:
buf - to set.
dataRect - defining the width, height and position of the data.

getRequiredBufferSize

public final int getRequiredBufferSize()
Returns the needed size of the ByteBuffer in bytes.

Returns:
size of the buffer

createCompatibleRasterData

public ByteBufferRasterData createCompatibleRasterData(int width,
                                                       int height)
Description copied from interface: RasterData
Returns a new RasterData with the same DataType and InterleaveType and all bands

Specified by:
createCompatibleRasterData in interface RasterData
Parameters:
width - width of the new raster
height - height of the new raster
Returns:
new empty raster

createCompatibleRasterData

public ByteBufferRasterData createCompatibleRasterData(RasterRect env)
Description copied from interface: RasterData
Returns a view as a new RasterData with the same DataType and InterleaveType but valid only for the given rect.

Specified by:
createCompatibleRasterData in interface RasterData
Parameters:
env - the raster rectangle defining the sample domain of this raster data.
Returns:
new raster backed by the readonly data of original raster.

createCompatibleRasterData

public RasterData createCompatibleRasterData(RasterRect sampleDomain,
                                             BandType[] bands)
Description copied from interface: RasterData
Returns a new RasterData with the same DataType and InterleaveType

Specified by:
createCompatibleRasterData in interface RasterData
Parameters:
sampleDomain - the raster rectangle defining the sample domain of this raster data.
bands - indices to the requested bands
Returns:
new empty raster

createCompatibleRasterData

public ByteBufferRasterData createCompatibleRasterData(BandType[] bands)
Description copied from interface: RasterData
Returns a new RasterData with the same size, DataType and InterleaveType

Specified by:
createCompatibleRasterData in interface RasterData
Parameters:
bands - definitions of the new rasterdata.
Returns:
new empty raster

createCompatibleRasterData

public ByteBufferRasterData createCompatibleRasterData()
Description copied from interface: RasterData
Returns a new RasterData with the same size, bands, DataType and InterleaveType

Specified by:
createCompatibleRasterData in interface RasterData
Returns:
new empty raster

asReadOnly

public RasterData asReadOnly()
Description copied from interface: RasterData
Return a read-only version of this RasterData. The result shares the same data as the original.

Specified by:
asReadOnly in interface RasterData
Returns:
a read-only RasterData

getDataType

public DataType getDataType()
Description copied from interface: RasterData
Returns the data type of the raster.

Specified by:
getDataType in interface RasterData
Returns:
data type of the raster

getBands

public int getBands()
Description copied from interface: RasterData
Returns the number of bands of the raster

Specified by:
getBands in interface RasterData
Returns:
the bands

getDataInfo

public RasterDataInfo getDataInfo()
Description copied from interface: RasterData
Returns an encapsulation of all available information of this raster data.

Specified by:
getDataInfo in interface RasterData
Returns:
available information of this raster data.

getOriginalDataInfo

public RasterDataInfo getOriginalDataInfo()
Returns:
the original datainfo object.

getOriginalHeight

public int getOriginalHeight()
Returns:
the underlying raster height.

getBytebufferDomain

public RasterRect getBytebufferDomain()
Returns:
the domain of validity of the byte buffer, which need not be the view on the data.

getOriginalWidth

public int getOriginalWidth()
Returns:
the underlying raster width.

getNullPixel

public byte[] getNullPixel(byte[] result)
Description copied from interface: RasterData
Returns the no data values for this raster, or the view of this rasters bands.

Specified by:
getNullPixel in interface RasterData
Parameters:
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

setNoDataValue

public void setNoDataValue(byte[] values)
Description copied from interface: RasterData
Sets the no data values for this raster

Specified by:
setNoDataValue in interface RasterData
Parameters:
values - an array with the null values

getColumns

public final int getColumns()
Description copied from interface: RasterData
Returns the width of the raster

Specified by:
getColumns in interface RasterData
Returns:
the width

getRows

public final int getRows()
Description copied from interface: RasterData
Returns the height of the raster

Specified by:
getRows in interface RasterData
Returns:
the height

getByteBuffer

public ByteBuffer getByteBuffer()
Returns:
The internal ByteBuffer.

checkBoundsEx

protected final void checkBoundsEx(int x,
                                   int y,
                                   int width,
                                   int height)
                            throws IndexOutOfBoundsException
Checks whether a given rect is inside the raster, throws an exception if outside.

Parameters:
x - The x position of the rect.
y - The y position of the rect.
width - The width of the rect.
height - The height of the rect.
Throws:
IndexOutOfBoundsException - if the given rect is outside the raster

checkBounds

protected final boolean checkBounds(int x,
                                    int y,
                                    int width,
                                    int height)
Checks whether a given rect is inside the raster.

Parameters:
x - The x position of the rect.
y - The y position of the rect.
width - The width of the rect.
height - The height of the rect.
Returns:
true if the given rect is inside the raster, else false

calculatePos

public final int calculatePos(int x,
                              int y)
Calculates the position of a pixel in the ByteBuffer. This method calculates the position of a pixel and returns the offset to this pixel in bytes. Use this method for direct access to ByteBuffers.

Parameters:
x - x coordinate
y - y coordinate
Returns:
byte offset to the pixel with the specified coordinate or -1 if outside of the bytebuffer.

calculatePos

public final int calculatePos(int x,
                              int y,
                              int bandOfView)
Calculates the position of a sample in the ByteBuffer. This method calculates the position of a pixel and returns the offset to this pixel in bytes. Use this method for direct access to ByteBuffers.

Parameters:
x - x coordinate
y - y coordinate
bandOfView - band index of the sample
Returns:
byte offset to the sample with the specified coordinate or -1 if outside of the bytebuffer.

calculateViewPos

public final int calculateViewPos(int x,
                                  int y)
Calculates the position of a pixel in a view (FloatBuffer, etc.) of the ByteBuffer. This method considers different sample sizes (eg. byte, float) and returns the position in sample strides (not byte strides). Use this method to get proper positions for ByteBuffer views like FloatBuffer, ShortBuffer, etc..

Parameters:
x - x coordinate
y - y coordinate
Returns:
offset to the pixel with the specified coordinates or -1 if outside of the bytebuffer.

calculateViewPos

public final int calculateViewPos(int x,
                                  int y,
                                  int band)
Calculates the position of a sample in a view (FloatBuffer, etc.) of the ByteBuffer. This method considers different sample sizes (eg. byte, float) and returns the position in sample stides (not byte strides). Use this method to get proper positions for ByteBuffer-views like FloatBuffer, ShortBuffer, etc..

Parameters:
x - x coordinate
y - y coordinate
band - band index of the sample
Returns:
offset to the sample with the specified coordinates

getBytes

public byte[] getBytes(int x,
                       int y,
                       int width,
                       int height,
                       int band,
                       byte[] result)
Description copied from interface: RasterData
Gets values from the specified rectangle and band. The result is stored row-ordered in a single array (e.g. {x0y0, x1y0, x2y0,...,x0y1...})

Specified by:
getBytes in interface RasterData
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getBytePixel

public byte[] getBytePixel(int x,
                           int y,
                           byte[] result)
Description copied from interface: RasterData
Returns a byte array with all sample values from coordinate x/y. The length of the array is equal to the number of bands.

Specified by:
getBytePixel in interface RasterData
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getByteSample

public byte getByteSample(int x,
                          int y,
                          int band)
Description copied from interface: RasterData
Returns a byte sample from coordinate x/y and selected band.

Specified by:
getByteSample in interface RasterData
band - band number for sample
Returns:
sample from selected coordinate and band

getDoubles

public double[] getDoubles(int x,
                           int y,
                           int width,
                           int height,
                           int band,
                           double[] result)
Description copied from interface: RasterData
Gets values from the specified rectangle and band. The result is stored row-ordered in a single array (e.g. {x0y0, x1y0, x2y0,...,x0y1...})

Specified by:
getDoubles in interface RasterData
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getDoublePixel

public double[] getDoublePixel(int x,
                               int y,
                               double[] result)
Description copied from interface: RasterData
Returns a double array with all sample values from coordinate x/y. The length of the array is equal to the number of bands.

Specified by:
getDoublePixel in interface RasterData
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getDoubleSample

public double getDoubleSample(int x,
                              int y,
                              int band)
Description copied from interface: RasterData
Returns a double sample from coordinate x/y and selected band.

Specified by:
getDoubleSample in interface RasterData
band - band number for sample
Returns:
sample from selected coordinate and band

getFloats

public float[] getFloats(int x,
                         int y,
                         int width,
                         int height,
                         int band,
                         float[] result)
Description copied from interface: RasterData
Gets values from the specified rectangle and band. The result is stored row-ordered in a single array (e.g. {x0y0, x1y0, x2y0,...,x0y1...})

Specified by:
getFloats in interface RasterData
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getFloatPixel

public float[] getFloatPixel(int x,
                             int y,
                             float[] result)
Description copied from interface: RasterData
Returns a float array with all sample values from coordinate x/y. The length of the array is equal to the number of bands.

Specified by:
getFloatPixel in interface RasterData
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getFloatSample

public float getFloatSample(int x,
                            int y,
                            int band)
Description copied from interface: RasterData
Returns a float sample from coordinate x/y and selected band.

Specified by:
getFloatSample in interface RasterData
band - band number for sample
Returns:
sample from selected coordinate and band

getInts

public int[] getInts(int x,
                     int y,
                     int width,
                     int height,
                     int band,
                     int[] result)
Description copied from interface: RasterData
Gets values from the specified rectangle and band. The result is stored row-ordered in a single array (e.g. {x0y0, x1y0, x2y0,...,x0y1...})

Specified by:
getInts in interface RasterData
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getIntPixel

public int[] getIntPixel(int x,
                         int y,
                         int[] result)
Description copied from interface: RasterData
Returns an integer array with all sample values from coordinate x/y. The length of the array is equal to the number of bands.

Specified by:
getIntPixel in interface RasterData
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getIntSample

public int getIntSample(int x,
                        int y,
                        int band)
Description copied from interface: RasterData
Returns an integer sample from coordinate x/y and selected band.

Specified by:
getIntSample in interface RasterData
band - band number for sample
Returns:
sample from selected coordinate and band

getPixel

public byte[] getPixel(int x,
                       int y,
                       byte[] result)
Description copied from interface: RasterData
Returns a pixel as byte array, regardless of the DataType. i.e. a FLOAT DataType results in a four byte array.

Specified by:
getPixel in interface RasterData
result - a byte array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getSample

public byte[] getSample(int x,
                        int y,
                        int band,
                        byte[] result)
Description copied from interface: RasterData
Returns a sample as byte array, regardless of the DataType. i.e. a FLOAT DataType results in a four byte array

Specified by:
getSample in interface RasterData
band - selected band
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getShorts

public short[] getShorts(int x,
                         int y,
                         int width,
                         int height,
                         int band,
                         short[] result)
Description copied from interface: RasterData
Gets values from the specified rectangle and band. The result is stored row-ordered in a single array (e.g. {x0y0, x1y0, x2y0,...,x0y1...})

Specified by:
getShorts in interface RasterData
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getShortPixel

public short[] getShortPixel(int x,
                             int y,
                             short[] result)
Description copied from interface: RasterData
Returns a short array with all sample values from coordinate x/y. The length of the array is equal to the number of bands.

Specified by:
getShortPixel in interface RasterData
result - an array to put the values into or null
Returns:
the result array or a new array, if the result array is null

getShortSample

public short getShortSample(int x,
                            int y,
                            int band)
Description copied from interface: RasterData
Returns a short sample from coordinate x/y and selected band.

Specified by:
getShortSample in interface RasterData
band - band number for sample
Returns:
sample from selected coordinate and band

getSubset

public ByteBufferRasterData getSubset(RasterRect sampleDomain)
Description copied from interface: RasterData
Returns new RasterData object for the specified rectangle.

Specified by:
getSubset in interface RasterData
Parameters:
sampleDomain - rectangle for subset
Returns:
selected subset

getSubset

public ByteBufferRasterData getSubset(RasterRect sampleDomain,
                                      BandType[] bands)
Description copied from interface: RasterData
Returns new single-band RasterData object for the specified rectangle.

Specified by:
getSubset in interface RasterData
Parameters:
sampleDomain - rectangle for subset
bands - selected band
Returns:
selected rectangle

setBytes

public void setBytes(int x,
                     int y,
                     int width,
                     int height,
                     int band,
                     byte[] values)
Description copied from interface: RasterData
Sets values from the array to the specified rectangle and band. The values must be stored row-ordered in a single array (e.g. {x0y0, x1y0, x2y0,...,x0y1...})

Specified by:
setBytes in interface RasterData
values - the samples to put into the raster

setBytePixel

public void setBytePixel(int x,
                         int y,
                         byte[] pixel)
Description copied from interface: RasterData
Sets a single pixel with byte values for each sample. The length of pixel array must be equal to the number of bands.

Specified by:
setBytePixel in interface RasterData
pixel - array with one sample per band

setByteSample

public void setByteSample(int x,
                          int y,
                          int band,
                          byte value)
Description copied from interface: RasterData
Sets a single byte sample on coordinate x/y and selected band.

Specified by:
setByteSample in interface RasterData
band - band number for sample
value - new value for sample

setDoubles

public void setDoubles(int x,
                       int y,
                       int width,
                       int height,
                       int band,
                       double[] values)
Description copied from interface: RasterData
Sets values from the array to the specified rectangle and band. The values must be stored row-ordered in a single array (e.g. {x0y0, x1y0, x2y0,...,x0y1...})

Specified by:
setDoubles in interface RasterData
values - the samples to put into the raster

dispose

public void dispose()
Description copied from interface: RasterData
Try to dispose all allocated memory of this data object.

Specified by:
dispose in interface RasterData

setDoublePixel

public void setDoublePixel(int x,
                           int y,
                           double[] pixel)
Description copied from interface: RasterData
Sets a single pixel with double values for each sample. The length of pixel array must be equal to the number of bands.

Specified by:
setDoublePixel in interface RasterData
pixel - array with one sample per band

setDoubleSample

public void setDoubleSample(int x,
                            int y,
                            int band,
                            double value)
Description copied from interface: RasterData
Sets a single double sample on coordinate x/y and selected band.

Specified by:
setDoubleSample in interface RasterData
band - band number for sample
value - new value for sample

setFloats

public void setFloats(int x,
                      int y,
                      int width,
                      int height,
                      int band,
                      float[] values)
Description copied from interface: RasterData
Sets values from the array to the specified rectangle and band. The values must be stored row-ordered in a single array (e.g. {x0y0, x1y0, x2y0,...,x0y1...})

Specified by:
setFloats in interface RasterData
values - the samples to put into the raster

setFloatPixel

public void setFloatPixel(int x,
                          int y,
                          float[] pixel)
Description copied from interface: RasterData
Sets a single pixel with float values for each sample. The length of pixel array must be equal to the number of bands.

Specified by:
setFloatPixel in interface RasterData
pixel - array with one sample per band

setFloatSample

public void setFloatSample(int x,
                           int y,
                           int band,
                           float value)
Description copied from interface: RasterData
Sets a single float sample on coordinate x/y and selected band.

Specified by:
setFloatSample in interface RasterData
band - band number for sample
value - new value for sample

setPixel

public void setPixel(int x,
                     int y,
                     byte[] result)
Description copied from interface: RasterData
Sets a pixel with data from a byte array, regardless of the DataType. i.e. a float sample must be packed as a four byte array.

Specified by:
setPixel in interface RasterData

setInts

public void setInts(int x,
                    int y,
                    int width,
                    int height,
                    int band,
                    int[] values)
Description copied from interface: RasterData
Sets values from the array to the specified rectangle and band. The values must be stored row-ordered in a single array (e.g. {x0y0, x1y0, x2y0,...,x0y1...})

Specified by:
setInts in interface RasterData
values - the samples to put into the raster

setIntPixel

public void setIntPixel(int x,
                        int y,
                        int[] pixel)
Description copied from interface: RasterData
Sets a single pixel with integer values for each sample. The length of pixel array must be equal to the number of bands.

Specified by:
setIntPixel in interface RasterData
pixel - array with one sample per band

setIntSample

public void setIntSample(int x,
                         int y,
                         int band,
                         int value)
Description copied from interface: RasterData
Sets a single integer sample on coordinate x/y and selected band.

Specified by:
setIntSample in interface RasterData
band - band number for sample
value - new value for sample

setShorts

public void setShorts(int x,
                      int y,
                      int width,
                      int height,
                      int band,
                      short[] values)
Description copied from interface: RasterData
Sets values from the array to the specified rectangle and band. The values must be stored row-ordered in a single array (e.g. {x0y0, x1y0, x2y0,...,x0y1...})

Specified by:
setShorts in interface RasterData
values - the samples to put into the raster

setShortPixel

public void setShortPixel(int x,
                          int y,
                          short[] pixel)
Description copied from interface: RasterData
Sets a single pixel with short values for each sample. The length of pixel array must be equal to the number of bands.

Specified by:
setShortPixel in interface RasterData
pixel - array with one sample per band

setShortSample

public void setShortSample(int x,
                           int y,
                           int band,
                           short value)
Description copied from interface: RasterData
Sets a single short sample on coordinate x/y and selected band.

Specified by:
setShortSample in interface RasterData
band - band number for sample
value - new value for sample

setSample

public void setSample(int x,
                      int y,
                      int band,
                      byte[] value)
Description copied from interface: RasterData
Sets a sample with data from a byte array, regardless of the DataType. i.e. a float must be packed as a four byte array

Specified by:
setSample in interface RasterData
band - selected band
value - array with the sample value

setSubset

public void setSubset(int x0,
                      int y0,
                      int width,
                      int height,
                      RasterData sourceRaster)
Description copied from interface: RasterData
Sets the raster with values from sourceRaster.

Specified by:
setSubset in interface RasterData
Parameters:
x0 - insert position
y0 - insert position
width - width of the subset
height - height of the subset
sourceRaster - data source to copy

setSubset

public void setSubset(int x0,
                      int y0,
                      int width,
                      int height,
                      int dstBand,
                      RasterData sourceRaster,
                      int srcBand)
Description copied from interface: RasterData
Sets a single band of the raster with values from one band of the sourceRaster.

Specified by:
setSubset in interface RasterData
Parameters:
x0 - insert position
y0 - insert position
width - width of the subset
height - height of the subset
dstBand - the index of the destination band
sourceRaster - data source to copy
srcBand - the index of the source band of sourceRaster

setSubset

public void setSubset(int dstX,
                      int dstY,
                      int width,
                      int height,
                      RasterData srcRaster,
                      int srcX,
                      int srcY)
Description copied from interface: RasterData
Sets the raster with values from sourceRaster.

Specified by:
setSubset in interface RasterData
Parameters:
dstX - insert position
dstY - insert position
width - width of the subset
height - height of the subset
srcRaster - data source to copy
srcX - x offset in the source raster
srcY - y offset in the source raster

setSubset

public void setSubset(int dstX,
                      int dstY,
                      int width,
                      int height,
                      int dstBand,
                      RasterData srcRaster,
                      int srcBand,
                      int srcX,
                      int srcY)
Description copied from interface: RasterData
Sets a single band of the raster with values from one band of the sourceRaster.

Specified by:
setSubset in interface RasterData
Parameters:
dstX - insert position
dstY - insert position
width - width of the subset
height - height of the subset
dstBand - the index of the destination band
srcRaster - data source to copy
srcBand - the index of the source band of sourceRaster
srcX - x offset in the source raster
srcY - y offset in the source raster

clampSize

protected static final int clampSize(int dstSize,
                                     int dstOrdinate,
                                     int srcSize,
                                     int srcOrdinate,
                                     int copySize)
Clamp to the minimal size of the given values.

Parameters:
dstSize - e.g. getWidth() or getHeight() of the destination raster.
dstOrdinate - e.g srcX, srcY, the location to put the data in destination raster.
srcSize - e.g. getWidth() or getHeight() of the source raster. *
srcOrdinate - e.g dstX, dstY, the location to read the data from the source raster.
copySize - e.g. width/height of rectangle to put data in this raster.
Returns:
the minimal value

toString

public String toString()
Overrides:
toString in class Object

min

protected static final int min(int... sizes)
Returns the smallest value of all ints.

Parameters:
sizes -
Returns:
the smallest value

createRasterDataInfo

protected RasterDataInfo createRasterDataInfo(BandType[] bands)
Create the raster data info object for the given bands, if empty or null the current dataInfo will be used.

Parameters:
bands -
Returns:
a new raster data info object with for the given bands.

getReader

public RasterReader getReader()
Returns:
the Reader which supplies this buffer with data, may be null


Copyright © 2011. All Rights Reserved.