- All Implemented Interfaces:
Serializable
,Function<GridCoverage,
,GridCoverage> UnaryOperator<GridCoverage>
DimensionalityReduction
specifies which dimensions to keep, and which grid
values to use for the omitted dimensions. This information allows the conversion from
a source GridGeometry
to a reduced grid geometry, and conversely.
Instances of DimensionalityReduction
are immutable and thread-safe.
Assumptions
The current implementation assumes that removing n dimensions in the grid extent causes the removal of exactly n dimensions in the Coordinate Reference System. However, the removed dimensions do not need to be at the same indices or in same order.- Since:
- 1.4
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
DimensionalityReduction
(GridGeometry source, BitSet gridAxes, MathTransformFactory factory) Reduces the dimension of the specified grid geometry by retaining the axes specified in the given bitset. -
Method Summary
Modifier and TypeMethodDescriptionapply
(GridCoverage source) Returns a grid coverage on which dimensionality reduction of the domain has been applied.apply
(GridExtent source) Returns a grid extent on which dimensionality reduction has been applied.apply
(GridGeometry source) Returns a grid geometry on which dimensionality reduction of the grid extent has been applied.apply
(DirectPosition source) Returns a coordinate tuple on which dimensionality reduction has been applied.Returns the grid geometry with only the retained grid axis dimension.int[]
Returns the indices of the source dimensions that are kept in the reduced grid geometry.Returns the grid coordinates used inreverse(…)
method calls for reconstituting some removed dimensions.Returns the grid geometry with all grid axis dimension.boolean
Returnstrue
if this object does not reduce any dimension.boolean
isReduced
(GridGeometry candidate) Returnstrue
if the given grid geometry is likely to be already reduced.boolean
isSlice()
Returnstrue
if this dimensionality reduction is a slice in the source coverage.static DimensionalityReduction
reduce
(GridGeometry source) Automatically reduces a grid geometry by removing all grid dimensions with an extent size of 1.static DimensionalityReduction
remove
(GridGeometry source, int... gridAxesToRemove) Reduces the dimension of the specified grid geometry by removing the specified axes.reverse
(GridExtent reduced) Returns a grid extent on which dimensionality reduction has been reverted.reverse
(GridGeometry reduced) Returns a grid geometry on which dimensionality reduction has been reverted.static DimensionalityReduction
select
(GridGeometry source, int... gridAxesToPass) Reduces the dimension of the specified grid geometry by retaining only the specified axes.static DimensionalityReduction
select2D
(GridGeometry source) A convenience method for selecting the two first dimensions of the specified grid geometry.withSliceByRatio
(double ratio) Returns a dimensional reduction with a relative slice position for every grid dimensions that have been removed.withSlicePoint
(long[] point) Returns a dimensional reduction which will use the given source grid indices forreverse(…)
operations.
-
Constructor Details
-
DimensionalityReduction
protected DimensionalityReduction(GridGeometry source, BitSet gridAxes, MathTransformFactory factory) throws FactoryException Reduces the dimension of the specified grid geometry by retaining the axes specified in the given bitset. Axes in the reduced grid geometry will be in the same order than in the source geometry:- Parameters:
source
- the grid geometry on which to select a subset of its grid dimensions.gridAxes
- bitmask of indices of source grid dimensions to keep in the reduced grid. Will be modified by this constructor for internal purpose.factory
- the factory to use for creating new math transforms, ornull
if none.- Throws:
FactoryException
- if the dimensions to keep cannot be separated from the dimensions to omit.
-
-
Method Details
-
select
Reduces the dimension of the specified grid geometry by retaining only the specified axes. Axes in the reduced grid geometry will be in the same order than in the source geometry: change of axis order and duplicated values in thegridAxesToPass
argument are ignored.- Parameters:
source
- the grid geometry to reduce.gridAxesToPass
- the grid axes to retain, ignoring order and duplicated values.- Returns:
- reduced grid geometry together with other information.
- Throws:
IndexOutOfBoundsException
- if a grid axis index is out of bounds.IllegalGridGeometryException
- if the dimensions to keep cannot be separated from the dimensions to omit.
-
select2D
A convenience method for selecting the two first dimensions of the specified grid geometry. This method can be used as a lambda function in resources query. Example:CoverageQuery query = new CoverageQuery(); query.setAxisSelection(DimensionalityReduction::select2D);
- Parameters:
source
- the grid geometry to reduce.- Returns:
- reduced grid geometry together with other information.
- Throws:
IndexOutOfBoundsException
- if the grid geometry does not have at least two dimensions.IllegalGridGeometryException
- if the dimensions to keep cannot be separated from the dimensions to omit.- See Also:
-
remove
Reduces the dimension of the specified grid geometry by removing the specified axes. Axes in the reduced grid geometry will be in the same order than in the source geometry: axis order and duplicated values in thegridAxesToRemove
argument are not significant.- Parameters:
source
- the grid geometry to reduce.gridAxesToRemove
- the grid axes to remove, ignoring order and duplicated values.- Returns:
- reduced grid geometry together with other information.
- Throws:
IndexOutOfBoundsException
- if a grid axis index is out of bounds.IllegalGridGeometryException
- if the dimensions to keep cannot be separated from the dimensions to omit.
-
reduce
Automatically reduces a grid geometry by removing all grid dimensions with an extent size of 1. Axes in the reduced grid geometry will be in the same order than in the source geometry.- Parameters:
source
- the grid geometry to reduce.- Returns:
- reduced grid geometry together with other information.
- Throws:
IncompleteGridGeometryException
- if the grid geometry has no extent.IllegalGridGeometryException
- if the dimensions to keep cannot be separated from the dimensions to omit.- See Also:
-
isIdentity
public boolean isIdentity()Returnstrue
if this object does not reduce any dimension. It may happen ifselect(…)
has been invoked with all axes to keep, or ifremove(…)
has been invoked with no axis to remove.- Returns:
- whether this
DimensionalityReduction
does nothing.
-
isSlice
public boolean isSlice()Returnstrue
if this dimensionality reduction is a slice in the source coverage. This is true if all removed dimensions either have a grid size of one cell, or have a slice coordinate specified.If this method returns
false
, then the results ofreverse(…)
method calls are potentially ambiguous and may cause aSubspaceNotSpecifiedException
to be thrown at rendering time.- Returns:
- whether this dimensionality reduction is a slice in the source coverage.
- See Also:
-
isReduced
Returnstrue
if the given grid geometry is likely to be already reduced. Current implementation checks only the number of dimensions.- Parameters:
candidate
- the grid geometry to test.- Returns:
- whether the given grid geometry is likely to be already reduced.
-
getReducedGridGeometry
Returns the grid geometry with only the retained grid axis dimension. The number of CRS dimensions should be reduced as well, but not necessarily in a one-to-one relationship.- Returns:
- the grid geometry with retained grid dimensions.
-
getSourceGridGeometry
Returns the grid geometry with all grid axis dimension. This is thesource
argument given to factory methods.- Returns:
- the grid geometry with all grid dimensions.
-
getSelectedDimensions
public int[] getSelectedDimensions()Returns the indices of the source dimensions that are kept in the reduced grid geometry.- Returns:
- indices of source grid dimensions that are retained in the reduced grid geometry.
-
getSliceCoordinates
Returns the grid coordinates used inreverse(…)
method calls for reconstituting some removed dimensions. Keys are indices of grid dimensions in the source that are not retained in the reduced grid geometry. Values are grid coordinates to assign to those dimensions when areverse(…)
method is executed.This map does not need to contain an entry for all removed dimensions. If no slice point is specified for a given dimension, then the
reverse(…)
methods will use the full range of grid coordinates specified in the source geometry. Often, those ranges have a size of 1, in which case methods such asGridCoverage.render(GridExtent)
will work anyway. If a removed source grid dimension had a size greater than 1 and no slice coordinates is specified; then thereverse(…)
methods in this class will still work but anSubspaceNotSpecifiedException
may be thrown later by other classes.This map is initially empty. Slice coordinates can be specified by calls to
withSlicePoint(long[])
orwithSliceByRatio(double)
.- Returns:
- source grid coordinates of the slice point used in
reverse(…)
method calls. - See Also:
-
apply
Returns a coordinate tuple on which dimensionality reduction has been applied. The coordinate reference system of the givensource
should be either null or equal (ignoring metadata) to the CRS of the source grid geometry. For performance reason, this is not verified unless assertions are enabled.- Parameters:
source
- the source coordinate tuple, ornull
.- Returns:
- the reduced coordinate tuple, or
null
if the given source was null.
-
apply
Returns a grid extent on which dimensionality reduction has been applied. If the given source isnull
, then this method returnsnull
. Nulls are accepted because they are valid argument values in calls toGridCoverage.render(GridExtent)
.- Parameters:
source
- the grid extent to reduce, ornull
.- Returns:
- the reduced grid extent. May be
source
, which may be null. - Throws:
MismatchedDimensionException
- if the given source does not have the expected number of dimensions.IllegalArgumentException
- if axis types are specified but inconsistent in at least one dimension.- See Also:
-
apply
Returns a grid geometry on which dimensionality reduction of the grid extent has been applied. It usually implies a reduction in the number of dimensions of the CRS as well, but not necessarily in same order.If the given source is
null
, then this method returnsnull
. Nulls are accepted because they are valid argument values in calls toGridCoverageResource.read(GridGeometry, int...)
.- Parameters:
source
- the grid geometry to reduce, ornull
.- Returns:
- the reduced grid geometry. May be
source
, which may be null. - Throws:
MismatchedDimensionException
- if the given source does not have the expected number of dimensions.IllegalArgumentException
- if axis types are specified but inconsistent in at least one dimension.- See Also:
-
apply
Returns a grid coverage on which dimensionality reduction of the domain has been applied. This is a reduction in the number of dimensions of the grid extent. It usually implies a reduction in the number of dimensions of the CRS as well, but not necessarily in same order. The sample dimensions (coverage range) are unmodified.The returned coverage is a view: changes in the source coverage are reflected immediately in the reduced coverage, and conversely.
Reversibility
IfisSlice()
returnsfalse
, then the results ofreverse(GridExtent)
are ambiguous and calls toGridCoverage.render(GridExtent)
may cause anSubspaceNotSpecifiedException
to be thrown. Unless the specifiedsource
grid coverage knows how to handle those cases.- Specified by:
apply
in interfaceFunction<GridCoverage,
GridCoverage> - Parameters:
source
- the grid coverage to reduce.- Returns:
- the reduced grid coverage, or
source
if this object is identity. - Throws:
MismatchedDimensionException
- if the given source does not have the expected number of dimensions.IllegalArgumentException
- if axis types are specified but inconsistent in at least one dimension.- See Also:
-
reverse
Returns a grid extent on which dimensionality reduction has been reverted. For all dimensions that were removed, grid coordinates will be set to the slice coordinates if specified, or to the original source grid coordinates otherwise. In the latter case, the reconstituted grid coordinates will be a single value ifisSlice()
returnstrue
(in which case the returned extent is unambiguous), or may be a (potentially ambiguous) range of values otherwise.Handling of null grid geometry
If the given extent isnull
, then this method returns an extent with slice coordinates if they are known. If no slice coordinate has been specified, then this method returnsnull
. Nulls are accepted because they are valid argument values in calls toGridCoverage.render(GridExtent)
.- Parameters:
reduced
- the reduced grid extent to revert, ornull
.- Returns:
- the source grid extent. May be
reduced
, which may be null. - Throws:
IncompleteGridGeometryException
- if the source grid geometry has no extent.MismatchedDimensionException
- if the given extent does not have the expected number of dimensions.IllegalArgumentException
- if axis types are specified but inconsistent in at least one dimension.
-
reverse
Returns a grid geometry on which dimensionality reduction has been reverted. For all dimensions that were removed, grid coordinates will be set to the slice coordinates if specified, or to the original source grid coordinates otherwise. In the latter case, the reconstituted dimensions will map a single coordinate value ifisSlice()
returnstrue
(in which case the returned grid geometry is unambiguous), or may map a (potentially ambiguous) range of grid coordinate values otherwise.Handling of null grid geometry
If the given geometry isnull
, then this method returns a grid geometry with the slice coordinates if they are known. If no slice coordinate has been specified, then this method returnsnull
. Nulls are accepted because they are valid argument values in calls toGridCoverageResource.read(GridGeometry, int...)
.- Parameters:
reduced
- the reduced grid geometry to revert, ornull
.- Returns:
- the source grid geometry. May be
reduced
, which may be null. - Throws:
IncompleteGridGeometryException
- if the source grid geometry has no extent.MismatchedDimensionException
- if the given geometry does not have the expected number of dimensions.IllegalArgumentException
- if axis types are specified but inconsistent in at least one dimension.
-
withSlicePoint
Returns a dimensional reduction which will use the given source grid indices forreverse(…)
operations. The length of the givenslicePoint
array shall be the number of dimensions of the source grid geometry. All given coordinate values shall be inside the source grid extent.- Parameters:
point
- grid coordinates of a point located on the slice.- Returns:
- the dimensionality reduction with the given slice point used for reverse operations.
- Throws:
IncompleteGridGeometryException
- if the source grid geometry has no extent.MismatchedDimensionException
- if the given point does not have the expected number of dimensions.PointOutsideCoverageException
- if the given point is outside the source grid extent.
-
withSliceByRatio
Returns a dimensional reduction with a relative slice position for every grid dimensions that have been removed. The relative position is specified by a ratio between 0 and 1 where 0 maps to low grid coordinates, 1 maps to high grid coordinates and 0.5 maps to the median position.- Parameters:
ratio
- the ratio to apply on all removed grid dimensions.- Returns:
- the dimensionality reduction with the given slice ratio applied.
- Throws:
IncompleteGridGeometryException
- if the source grid geometry has no extent.IllegalArgumentException
- if the given ratio is not between 0 and 1 inclusive.- See Also:
-