Package org.apache.sis.coverage.grid
Class GridCoverageProcessor
java.lang.Object
org.apache.sis.coverage.grid.GridCoverageProcessor
- All Implemented Interfaces:
Cloneable
A predefined set of operations on grid coverages as convenience methods.
Thread-safety
GridCoverageProcessor
is safe for concurrent use in multi-threading environment.- Since:
- 1.1
- Version:
- 1.3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Types of changes that a coverage processor can do for executing an operation more efficiently. -
Field Summary
FieldsModifier 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.private static final WeakHashSet
<ImageProcessor> ConfiguredImageProcessor
instances used byGridCoverage
s created by processors. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new processor with default configuration.GridCoverageProcessor
(ImageProcessor processor) Creates a new processor initialized to the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a coverage processor with the same configuration than this processor.convert
(GridCoverage source, org.opengis.referencing.operation.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.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.javax.measure.Quantity<?>[]
Returns hints about the desired positional accuracy, in "real world" units or in pixel units.int
hashCode()
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).(package private) static void
recoverableException
(String caller, Exception ex) Invoked when an ignorable exception occurred.resample
(GridCoverage source, GridGeometry target) Creates a new coverage with a different grid extent, resolution or coordinate reference system.resample
(GridCoverage source, org.opengis.referencing.crs.CoordinateReferenceSystem target) Creates a new coverage with a different coordinate reference system.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
(javax.measure.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.(package private) static ImageProcessor
unique
(ImageProcessor image) Returns an unique instance of the given processor.
-
Field Details
-
PROCESSORS
ConfiguredImageProcessor
instances used byGridCoverage
s created by processors. We use this set for sharing common instances inGridCoverage
instances, which is okay provided that we do not modify theImageProcessor
configuration. -
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
-
unique
Returns an unique instance of the given processor. Both the given and the returned processors shall be unmodified, because they may be shared by manyGridCoverage
instances. -
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:
-
getPositionalAccuracyHints
public javax.measure.Quantity<?>[] 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
public void setPositionalAccuracyHints(javax.measure.Quantity<?>... hints) 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
-
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:
-
mask
public GridCoverage mask(GridCoverage source, RegionOfInterest mask, boolean maskInside) throws org.opengis.referencing.operation.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.- 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:
org.opengis.referencing.operation.TransformException
- if ROI coordinates cannot be transformed to grid coordinates.- Since:
- 1.2
- See Also:
-
convert
public GridCoverage convert(GridCoverage source, org.opengis.referencing.operation.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.- 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.
- 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
public GridCoverage resample(GridCoverage source, GridGeometry target) throws org.opengis.referencing.operation.TransformException 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.
- 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.org.opengis.referencing.operation.TransformException
- if some coordinates cannot be transformed to the specified target.- See Also:
-
resample
public GridCoverage resample(GridCoverage source, org.opengis.referencing.crs.CoordinateReferenceSystem target) throws org.opengis.referencing.operation.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.org.opengis.referencing.operation.TransformException
- if some coordinates cannot be transformed to the specified target.- Since:
- 1.3
-
recoverableException
Invoked when an ignorable exception occurred.- Parameters:
caller
- the method where the exception occurred.ex
- the ignorable exception.
-
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.
-