Package org.apache.sis.coverage.grid
Class BufferedGridCoverage
java.lang.Object
org.apache.sis.coverage.BandedCoverage
org.apache.sis.coverage.grid.GridCoverage
org.apache.sis.coverage.grid.BufferedGridCoverage
Basic access to grid data values backed by a n-dimensional
DataBuffer
.
Those data can be shown as an untiled RenderedImage
.
Images are created when render(GridExtent)
is invoked instead of at construction time.
This delayed construction makes this class better suited to n-dimensional grids since
those grids cannot be wrapped into a single RenderedImage
.
Comparison with alternatives:
this class expects all data to reside in-memory and does not support tiling.
Pixels are stored in a row-major fashion with all bands in a single array or one array per band.
By contrast,
The number of bands is determined by the number of GridCoverage2D
allows more flexibility in data layout and supports tiling with data
loaded or computed on-the-fly, but is restricted to two-dimensional images (which may be slices in a
n-dimensional grid).SampleDimension
s specified at construction time.
The number of banks is either 1 or the number of bands.
- If the number of banks is 1, all data are packed in a single array with band indices varying fastest, then column indices (x), then row indices (y), then other dimensions.
- If the number of banks is greater than 1, then each band is stored in a separated array. In each array, sample values are stored with column indices (x) varying fastest, then row indices (y), then other dimensions. In the two-dimensional case, this layout is also known as row-major.
GridExtent
of the geometry given at
construction time. By default the extent size in the two first dimensions
will define the image width and height,
but different dimensions may be used depending on which dimensions are identified as the
subspace dimensions.- Since:
- 1.1
- Version:
- 1.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Implementation of evaluator returned byBandedCoverage.evaluator()
.Nested classes/interfaces inherited from class org.apache.sis.coverage.grid.GridCoverage
GridCoverage.Evaluator, GridCoverage.Lazy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Cache
<GridExtent, RenderedImage> Cache of rendered images produced by calls torender(GridExtent)
.protected final DataBuffer
The sample values, potentially multi-banded.Fields inherited from class org.apache.sis.coverage.grid.GridCoverage
gridGeometry
-
Constructor Summary
ConstructorsConstructorDescriptionBufferedGridCoverage
(GridGeometry grid, List<? extends SampleDimension> bands, int dataType) Constructs a grid coverage using the specified grid geometry, sample dimensions and data type.BufferedGridCoverage
(GridGeometry domain, List<? extends SampleDimension> range, DataBuffer data) Constructs a grid coverage using the specified grid geometry, sample dimensions and data buffer. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
configure
(ImageRenderer renderer) Invoked by the default implementation ofrender(GridExtent)
for completing the renderer configuration before to create an image.Creates a new function for computing or interpolating sample values at given locations.(package private) final DataType
Returns the constant identifying the primitive type used for storing sample values.private static long
getSampleCount
(GridExtent extent, long nbSamples) Returns the number of cells in the given extent multiplied by the number of bands.render
(GridExtent sliceExtent) Returns a two-dimensional slice of grid data as a rendered image.Methods inherited from class org.apache.sis.coverage.grid.GridCoverage
appendDataLayout, convert, createConvertedValues, forConvertedValues, getCoordinateReferenceSystem, getEnvelope, getGridGeometry, getSampleDimensions, toString, toTree
-
Field Details
-
data
The sample values, potentially multi-banded. The bands may be stored either in a single bank (pixel interleaved image) or in different banks (banded image). This class detects automatically which of those two sample models is used whenrender(GridExtent)
is invoked.Sample values in this buffer shall not be packed.
-
cachedRenderings
Cache of rendered images produced by calls torender(GridExtent)
. Those images are cached because, even if they are cheap to create, they may become the source of a chain of operations for statistics, image resampling, etc. Caching the source image preserves not only theRenderedImage
instance created by therender(GridExtent)
method, but also the chain of operations potentially derived from that image.Usage
Implementation ofrender(GridExtent)
method can be like below:
-
-
Constructor Details
-
BufferedGridCoverage
public BufferedGridCoverage(GridGeometry domain, List<? extends SampleDimension> range, DataBuffer data) Constructs a grid coverage using the specified grid geometry, sample dimensions and data buffer. This method stores the given buffer by reference (no copy). The bands in the given buffer can be stored either in a single bank (pixel interleaved image) or in different banks (banded image). This class detects automatically which of those two sample models is used (see class javadoc for more information).Note that
DataBuffer
does not contain any information about image size. Consequently,render(GridExtent)
depends on the domainGridExtent
, which must be accurate. If the extent size does not reflect accurately the image size, then the image will not be rendered properly.- Parameters:
domain
- the grid extent, CRS and conversion from cell indices to CRS.range
- sample dimensions for each image band.data
- the sample values, potentially multi-banded.- Throws:
NullPointerException
- if an argument isnull
.IllegalArgumentException
- if the data buffer has an incompatible number of banks.IllegalGridGeometryException
- if the grid extent is larger than the data buffer capacity.ArithmeticException
- if the number of cells is larger than 64 bits integer capacity.
-
BufferedGridCoverage
Constructs a grid coverage using the specified grid geometry, sample dimensions and data type. This constructor creates a single-bankDataBuffer
(pixel interleaved sample model) with all sample values initialized to zero.- Parameters:
grid
- the grid extent, CRS and conversion from cell indices to CRS.bands
- sample dimensions for each image band.dataType
- one ofDataBuffer.TYPE_*
constants, the native data type used to store the coverage values.- Throws:
ArithmeticException
- if the grid size is too large.
-
-
Method Details
-
getSampleCount
Returns the number of cells in the given extent multiplied by the number of bands.- Parameters:
extent
- the extent for which to get the number of cells.nbSamples
- number of bands.- Returns:
- number of cells multiplied by the number of bands.
- Throws:
ArithmeticException
- if the number of samples exceeds 64-bits integer capacity.
-
getBandType
Returns the constant identifying the primitive type used for storing sample values.- Overrides:
getBandType
in classGridCoverage
-
evaluator
Creates a new function for computing or interpolating sample values at given locations.Multi-threading
Evaluator
s are not thread-safe. For computing sample values concurrently, a newGridCoverage.Evaluator
instance should be created for each thread.- Overrides:
evaluator
in classGridCoverage
- Returns:
- a new function for computing or interpolating sample values.
-
render
Returns a two-dimensional slice of grid data as a rendered image. This method returns a view; sample values are not copied.The default implementation prepares an
ImageRenderer
, then invokesconfigure(ImageRenderer)
for allowing subclasses to complete the renderer configuration before to create the image.- Specified by:
render
in classGridCoverage
- Parameters:
sliceExtent
- a subspace of this grid coverage extent where all dimensions except two have a size of 1 cell. May benull
if this grid coverage has only two dimensions with a size greater than 1 cell.- Returns:
- the grid slice as a rendered image.
-
configure
Invoked by the default implementation ofrender(GridExtent)
for completing the renderer configuration before to create an image. The default implementation does nothing.Some example of methods that subclasses may want to use are:
- Parameters:
renderer
- the renderer to configure before to create an image.- Since:
- 1.3
-