- All Implemented Interfaces:
Cloneable
GridCoverageProcessor
can be configured for the following aspects:
- Interpolation method to use during resampling operations.
- Fill values to use for cells that cannot be computed.
- Colorization algorithm to apply for colorizing a computed image.
- Positional accuracy hints for enabling the use of faster algorithm when a lower accuracy is acceptable.
- Optimizations to enable.
Thread-safety
GridCoverageProcessor
is safe for concurrent use in multi-threading environment.- Since:
- 1.1
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Types of changes that a coverage processor can do for executing an operation more efficiently. -
Field Summary
Modifier and TypeFieldDescriptionprotected final ImageProcessor
The processor to use for operations on two-dimensional slices.protected final EnumSet
<GridCoverageProcessor.Optimization> The set of optimizations that are enabled. -
Constructor Summary
ConstructorDescriptionCreates a new processor with default configuration.GridCoverageProcessor
(ImageProcessor processor) Creates a new processor initialized to the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionaggregateRanges
(GridCoverage... sources) Aggregates in a single coverage the ranges of all specified coverages, in order.aggregateRanges
(GridCoverage[] sources, int[][] bandsPerSource) Aggregates in a single coverage the specified bands of a sequence of source coverages, in order.clone()
Returns a coverage processor with the same configuration than this processor.convert
(GridCoverage source, MathTransform1D[] converters, Function<SampleDimension.Builder, SampleDimension> sampleDimensionModifier) Returns a coverage with sample values converted by the given functions.boolean
Returnstrue
if the given object is a coverage processor of the same class with the same configuration.Returns the colorization algorithm to apply on computed images.Number[]
Returns the values to use for pixels that cannot be computed.Returns the interpolation method to use for resampling operations.Returns the set of optimizations that are enabled.Quantity<?>[]
Returns hints about the desired positional accuracy, in "real world" units or in pixel units.int
Returns a hash code value for this coverage processor based on its current configuration.mask
(GridCoverage source, RegionOfInterest mask, boolean maskInside) Applies a mask defined by a region of interest (ROI).reduceDimensionality
(GridCoverage source) Automatically reduces a grid coverage dimensionality by removing all grid axes with an extent size of 1.removeGridDimensions
(GridCoverage source, int... gridAxesToRemove) Creates a coverage trimmed from the specified grid dimensions.resample
(GridCoverage source, GridGeometry target) Creates a new coverage with a different grid extent, resolution or coordinate reference system.resample
(GridCoverage source, CoordinateReferenceSystem target) Creates a new coverage with a different coordinate reference system.selectGridDimensions
(GridCoverage source, int... gridAxesToPass) Creates a coverage containing only the specified grid dimensions.selectSampleDimensions
(GridCoverage source, int... bands) Selects a subset of sample dimensions (bands) in the given coverage.void
setColorizer
(Colorizer colorizer) Sets the colorization algorithm to apply on computed images.void
setFillValues
(Number... values) Sets the values to use for pixels that cannot be computed.void
setInterpolation
(Interpolation method) Sets the interpolation method to use for resampling operations.void
Specifies the set of optimizations to enable.void
setPositionalAccuracyHints
(Quantity<?>... hints) Sets hints about desired positional accuracy, in "real world" units or in pixel units.shiftGrid
(GridCoverage source, long... translation) Translates grid coordinates by the given amount of cells without changing "real world" coordinates.visualize
(GridCoverage source, GridExtent slice) Renders the given grid coverage as an image suitable for displaying purpose.
-
Field Details
-
imageProcessor
The processor to use for operations on two-dimensional slices. -
optimizations
The set of optimizations that are enabled. By default, this set contains all enumeration values.- Since:
- 1.3
- See Also:
-
-
Constructor Details
-
GridCoverageProcessor
public GridCoverageProcessor()Creates a new processor with default configuration. -
GridCoverageProcessor
Creates a new processor initialized to the given configuration.- Parameters:
processor
- the processor to use for operations on two-dimensional slices.
-
-
Method Details
-
getInterpolation
Returns the interpolation method to use for resampling operations. The default implementation delegates to the image processor.- Returns:
- interpolation method to use in resampling operations.
- See Also:
-
setInterpolation
Sets the interpolation method to use for resampling operations. The default implementation delegates to the image processor.- Parameters:
method
- interpolation method to use in resampling operations.- See Also:
-
getFillValues
Returns the values to use for pixels that cannot be computed. The default implementation delegates to the image processor.- Returns:
- fill values to use for pixels that cannot be computed, or
null
for the defaults. - Since:
- 1.2
- See Also:
-
setFillValues
Sets the values to use for pixels that cannot be computed. The default implementation delegates to the image processor.- Parameters:
values
- fill values to use for pixels that cannot be computed, ornull
for the defaults.- Since:
- 1.2
- See Also:
-
getColorizer
Returns the colorization algorithm to apply on computed images. The default implementation delegates to the image processor.- Returns:
- colorization algorithm to apply on computed image, or
null
for default. - Since:
- 1.4
- See Also:
-
setColorizer
Sets the colorization algorithm to apply on computed images. The colorizer is used byconvert(…)
andaggregateRanges(…)
operations among others. The default implementation delegates to the image processor.- Parameters:
colorizer
- colorization algorithm to apply on computed image, ornull
for default.- Since:
- 1.4
- See Also:
-
getPositionalAccuracyHints
Returns hints about the desired positional accuracy, in "real world" units or in pixel units. The default implementation delegates to the image processor.- Returns:
- desired accuracy in no particular order, or an empty array if none.
- See Also:
-
setPositionalAccuracyHints
Sets hints about desired positional accuracy, in "real world" units or in pixel units. The default implementation delegates to the image processor.- Parameters:
hints
- desired accuracy in no particular order, or anull
array if none. Null elements in the array are ignored.- See Also:
-
getOptimizations
Returns the set of optimizations that are enabled. By default, the returned set contains all optimizations.The returned set is a copy. Changes in this set will not affect the state of this processor.
- Returns:
- copy of the set of optimizations that are enabled.
- Since:
- 1.3
-
setOptimizations
Specifies the set of optimizations to enable. All optimizations not in the given set will be disabled.- Parameters:
enabled
- set of optimizations to enable.- Since:
- 1.3
-
mask
public GridCoverage mask(GridCoverage source, RegionOfInterest mask, boolean maskInside) throws TransformException Applies a mask defined by a region of interest (ROI). IfmaskInside
istrue
, then all pixels inside the given ROI are set to the fill values. IfmaskInside
isfalse
, then the mask is reversed: the pixels set to fill values are the ones outside the ROI.Properties used
This operation uses the following properties in addition to method parameters:- Fill values values to assign to pixels inside/outside the region of interest.
- Parameters:
source
- the coverage on which to apply a mask.mask
- region (in arbitrary CRS) of the mask.maskInside
-true
for masking pixels inside the shape, orfalse
for masking outside.- Returns:
- a coverage with mask applied.
- Throws:
TransformException
- if ROI coordinates cannot be transformed to grid coordinates.- Since:
- 1.2
- See Also:
-
convert
public GridCoverage convert(GridCoverage source, MathTransform1D[] converters, Function<SampleDimension.Builder, SampleDimension> sampleDimensionModifier) Returns a coverage with sample values converted by the given functions. The number of sample dimensions in the returned coverage is the length of theconverters
array, which must be greater than 0 and not greater than the number of sample dimensions in the source coverage. If theconverters
array length is less than the number of source sample dimensions, then all sample dimensions at index ≥converters.length
will be ignored.Sample dimensions customization
By default, this method creates new sample dimensions with the same names and categories than in the previous coverage, but with sample ranges converted using the given converters and with units of measurement omitted. This behavior can be modified by specifying a non-nullsampleDimensionModifier
function. If non-null, that function will be invoked with, as input, a pre-configured sample dimension builder. ThesampleDimensionModifier
function can change the sample dimension name or rebuild the categories.Result relationship with source
If the source coverage is backed by aWritableRenderedImage
, then changes in the source coverage are reflected in the returned coverage and conversely.Properties used
This operation uses the following properties in addition to method parameters:- Colorizer for customizing the rendered image color model.
- Parameters:
source
- the coverage for which to convert sample values.converters
- the transfer functions to apply on each sample dimension of the source coverage.sampleDimensionModifier
- a callback for modifying theSampleDimension.Builder
default configuration for each sample dimension of the target coverage, ornull
if none.- Returns:
- the coverage which computes converted values from the given source.
- Since:
- 1.3
- See Also:
-
shiftGrid
Translates grid coordinates by the given amount of cells without changing "real world" coordinates. The translated grid has the same size than the source, i.e. both low and high grid coordinates are displaced by the same amount of cells. The "grid to CRS" transforms are adjusted accordingly in order to map to the same "real world" coordinates.Number of arguments
Thetranslation
array length should be equal to the number of dimensions in the source coverage. If the array is shorter, missing values default to 0 (i.e. no translation in unspecified dimensions). If the array is longer, extraneous values are ignored.Optimizations
The following optimizations are applied by default and can be disabled if desired:GridCoverageProcessor.Optimization.REPLACE_SOURCE
for merging many calls of thistranslate(…)
method into a single translation.
Properties used
This operation uses the following properties in addition to method parameters:- (none)
- Parameters:
source
- the grid coverage to translate.translation
- translation to apply on each grid axis in order.- Returns:
- a grid coverage whose grid coordinates (both low and high ones) and the "grid to CRS" transforms have been translated by given amounts. If the given translation is a no-op (no value or only 0 ones), then the source is returned as is.
- Throws:
ArithmeticException
- if the translation results in coordinates that overflow 64-bits integer.- Since:
- 1.3
- See Also:
-
resample
Creates a new coverage with a different grid extent, resolution or coordinate reference system. The desired properties are specified by theGridGeometry
argument, which may be incomplete. The missing grid geometry components are completed as below:Default values for undefined grid geometry components Component Default value Grid extent A default size preserving resolution at source point of interest. Grid to CRS transform Whatever it takes for fitting data inside the supplied extent. Coordinate reference system Same as source coverage. setInterpolation(Interpolation)
. If the grid coverage values are themselves interpolated, this method tries to use the original data. The intent is to avoid adding interpolations on top of other interpolations.Optimizations
The following optimizations are applied by default and can be disabled if desired:GridCoverageProcessor.Optimization.REPLACE_SOURCE
for merging many calls ofresample(…)
ortranslate(…)
method into a single resampling.GridCoverageProcessor.Optimization.REPLACE_OPERATION
for replacingresample(…)
operation bytranslate(…)
when possible.
Properties used
This operation uses the following properties in addition to method parameters:- Interpolation method (nearest neighbor, bilinear, etc).
- Fill values for pixels outside source image.
- Positional accuracy hints for enabling faster resampling at the cost of lower precision.
- Parameters:
source
- the grid coverage to resample.target
- the desired geometry of returned grid coverage. May be incomplete.- Returns:
- a grid coverage with the characteristics specified in the given grid geometry.
- Throws:
IncompleteGridGeometryException
- if the source grid geometry is missing an information. It may be the source CRS, the source extent, etc. depending on context.TransformException
- if some coordinates cannot be transformed to the specified target.- See Also:
-
resample
public GridCoverage resample(GridCoverage source, CoordinateReferenceSystem target) throws TransformException Creates a new coverage with a different coordinate reference system. The grid extent and "grid to CRS" transform are determined automatically with default values preserving the resolution of source coverage at its point of interest.See
resample(GridCoverage, GridGeometry)
for more information about interpolation and allowed optimizations.- Parameters:
source
- the grid coverage to resample.target
- the desired coordinate reference system.- Returns:
- a grid coverage with the given coordinate reference system.
- Throws:
IncompleteGridGeometryException
- if the source grid geometry is missing an information.TransformException
- if some coordinates cannot be transformed to the specified target.- Since:
- 1.3
-
reduceDimensionality
Automatically reduces a grid coverage dimensionality by removing all grid axes with an extent size of 1. Axes in the reduced grid coverage will be in the same order than in the source coverage.- Parameters:
source
- the coverage to reduce to a lower number of dimensions.- Returns:
- the reduced grid coverage, or
source
if no grid dimensions can be removed. - Since:
- 1.4
- See Also:
-
removeGridDimensions
Creates a coverage trimmed from the specified grid dimensions. This is a dimensionality reduction operation applied to the coverage domain. The dimensions to remove are specified as indices of grid extent axes. It may be the same indices than the indices of the CRS axes which will be removed, but not necessarily.Constraints
If the source coverage contains dimensions that are not separable and if only a subset of those dimensions are specified for removal, then this method will throw anIllegalGridGeometryException
.For each dimension that is removed, the size of the grid extent must be 1 cell. If this condition does not hold, then this method will throw a
SubspaceNotSpecifiedException
. If desired, this restriction can be relaxed by direct use ofDimensionalityReduction
as below, where (x, y, z, t) are grid coordinates of a point in the desired slice:var reduction = DimensionalityReduction.remove(source.getGridGeometry(), gridAxesToPass); reduction = reduction.withSlicePoint(x, y, z, t); GridCoverage output = reduction.apply(source);
withSlicePoint(…)
call can be omitted if the caller knows that the source coverage can handle ambiguous grid extents.- Parameters:
source
- the coverage to reduce to a lower number of dimensions.gridAxesToRemove
- indices of each grid dimension to strip from result. Duplicated values are ignored.- Returns:
- the reduced grid coverage, or
source
if no grid dimensions was specified. - Throws:
IndexOutOfBoundsException
- if a grid axis index is out of bounds.SubspaceNotSpecifiedException
- if at least one removed dimension has a grid extent size larger than 1 cell.IllegalGridGeometryException
- if the dimensions to keep cannot be separated from the dimensions to omit.- Since:
- 1.4
- See Also:
-
selectGridDimensions
Creates a coverage containing only the specified grid dimensions. This is a dimensionality reduction operation applied to the coverage domain. The dimensions to keep are specified as indices of grid extent axes. It may be the same indices than the indices of the CRS axes which will pass through, but not necessarily.The axis order in the returned coverage is always the same as in the given
source
coverage, whatever the order in which axes are specified as input in thegridAxesToPass
array. Duplicated values in the array are also ignored.Constraints
If the source coverage contains dimensions that are not separable and if only a subset of those dimensions are selected in thegridAxesToPass
array, then this method will throw anIllegalGridGeometryException
.For each dimension that is not passed to the output grid coverage, the size of the grid extent must be 1 cell. If this condition does not hold, then this method will throw a
SubspaceNotSpecifiedException
. If desired, this restriction can be relaxed by direct use ofDimensionalityReduction
as below, where (x, y, z, t) are grid coordinates of a point in the desired slice:var reduction = DimensionalityReduction.select(source.getGridGeometry(), gridAxesToPass); reduction = reduction.withSlicePoint(x, y, z, t); GridCoverage output = reduction.apply(source);
withSlicePoint(…)
call can be omitted if the caller knows that the source coverage can handle ambiguous grid extents.- Parameters:
source
- the coverage to reduce to a lower number of dimensions.gridAxesToPass
- indices of each grid dimension to maintain in result. Order and duplicated values are ignored.- Returns:
- the reduced grid coverage, or
source
if all grid dimensions where specified. - Throws:
IndexOutOfBoundsException
- if a grid axis index is out of bounds.SubspaceNotSpecifiedException
- if at least one removed dimension has a grid extent size larger than 1 cell.IllegalGridGeometryException
- if the dimensions to keep cannot be separated from the dimensions to omit.- Since:
- 1.4
- See Also:
-
selectSampleDimensions
Selects a subset of sample dimensions (bands) in the given coverage. This method can also be used for changing sample dimension order or for repeating the same sample dimension from the source coverage. If the specifiedbands
indices select all sample dimensions in the same order, thensource
is returned directly.- Parameters:
source
- the coverage in which to select sample dimensions.bands
- indices of sample dimensions to retain.- Returns:
- coverage width selected sample dimensions.
- Throws:
IllegalArgumentException
- if a sample dimension index is invalid.- Since:
- 1.4
- See Also:
-
aggregateRanges
Aggregates in a single coverage the ranges of all specified coverages, in order. The list of sample dimensions of the aggregated coverage will be the concatenation of the lists from all sources.This convenience method delegates to
aggregateRanges(GridCoverage[], int[][])
. See that method for more information on restrictions.- Parameters:
sources
- coverages whose ranges shall be aggregated, in order. At least one coverage must be provided.- Returns:
- the aggregated coverage, or
sources[0]
returned directly if only one coverage was supplied. - Throws:
IllegalGridGeometryException
- if a grid geometry is not compatible with the others.- Since:
- 1.4
- See Also:
-
aggregateRanges
Aggregates in a single coverage the specified bands of a sequence of source coverages, in order. This method performs the same work thanaggregateRanges(GridCoverage...)
, but with the possibility to specify the sample dimensions to retain in each source coverage. ThebandsPerSource
argument specifies the sample dimensions to keep, in order. That array can benull
for selecting all sample dimensions in all source coverages, or may containnull
elements for selecting all sample dimensions of the corresponding coverage. An empty array element (i.e. zero sample dimension to select) discards the corresponding source coverage.Restrictions
- All coverage shall use the same CRS.
- All coverage shall use the same grid to CRS transform except for translation terms.
- Translation terms in grid to CRS can differ only by an integer amount of grid cells.
- The intersection of the domain of all coverages shall be non-empty.
- All coverages shall use the same data type in their rendered image.
- Parameters:
sources
- coverages whose bands shall be aggregated, in order. At least one coverage must be provided.bandsPerSource
- bands to use for each source coverage, in order. May containnull
elements.- Returns:
- the aggregated coverage, or one of the sources if it can be used directly.
- Throws:
IllegalGridGeometryException
- if a grid geometry is not compatible with the others.IllegalArgumentException
- if some band indices are duplicated or outside their range of validity.- Since:
- 1.4
- See Also:
-
visualize
Renders the given grid coverage as an image suitable for displaying purpose. The resulting image is for visualization only and should not be used for computational purposes. There is no guarantee about the number of bands in returned image or about which formula is used for converting floating point values to integer values.How to specify colors
The image colors can be controlled by theColorizer
set on this coverage processor. The recommended way is to associate colors to category names, units of measurement or other category properties. Example:Map<String,Color[]> colors = Map.of( "Temperature", new Color[] {Color.BLUE, Color.MAGENTA, Color.RED}, "Wind speed", new Color[] {Color.GREEN, Color.CYAN, Color.BLUE}); processor.setColorizer(Colorizer.forCategories((category) -> colors.get(category.getName().toString(Locale.ENGLISH)))); RenderedImage visualization = processor.visualize(source, slice);
Properties used
This operation uses the following properties in addition to method parameters:- Colorizer for customizing the rendered image color model.
- Parameters:
source
- the grid coverage to visualize.slice
- the slice and extent to render, ornull
for the whole coverage.- Returns:
- rendered image for visualization purposes only.
- Throws:
IllegalArgumentException
- if the given extent does not have the same number of dimensions than the specified coverage or does not intersect.- Since:
- 1.4
- See Also:
-
equals
Returnstrue
if the given object is a coverage processor of the same class with the same configuration. -
hashCode
public int hashCode()Returns a hash code value for this coverage processor based on its current configuration. -
clone
Returns a coverage processor with the same configuration than this processor.
-