Class GridDerivation
GridDerivation are created by calls to GridGeometry.derive().
 Properties of the desired grid geometry can be specified by calls to the following methods,
 in that order (each method is optional):
 - rounding(GridRoundingMode),- margin(int...)and/or- chunkSize(int...)in any order
- subgrid(GridGeometry),- subgrid(Envelope, double...)or- subgrid(GridExtent, long...)
- slice(DirectPosition)and/or- sliceByRatio(double, int...)
build().
 The getIntersection() method can also be invoked for the GridExtent part without subsampling.
 Multi-dimensional grids
All methods in this class preserve the number of dimensions. For example, theslice(DirectPosition) method
 sets the grid size to 1 in all dimensions specified by the slice point,
 but does not remove those dimensions from the grid geometry.
 For dimensionality reduction, see GridGeometry.selectDimensions(int[]).- Since:
- 1.0
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final GridGeometryThe base grid geometry from which to derive a new grid geometry.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedGridDerivation(GridGeometry base) Creates a new builder for deriving a grid geometry from the specified base.
- 
Method SummaryModifier and TypeMethodDescriptionbuild()Builds a grid geometry with the configuration specified by the other methods in thisGridDerivationclass.chunkSize(int... cellCounts) Specifies the size of tiles or chunks in the base grid geometry.clipping(GridClippingMode mode) Specifies whether to clip the derived grid extent to the extent of the base grid geometry.getGridTransform(PixelInCell anchor) Returns the transform from derived grid coordinates to base grid coordinates.Returns the extent of the modified grid geometry, ignoring subsampling or changes in resolution.long[]Returns the strides for accessing cells along each axis of the base grid.long[]Returns the offsets to be subtracted from pixel coordinates before subsampling.booleanReturns whether the conversion from the base grid to the derived grid contains a scale factor.margin(int... cellCounts) Specifies an number of cells by which to expandGridExtentafter rounding.maximumSubsampling(int[] subsampling) Deprecated.maximumSubsampling(long... subsampling) Specifies the maximum subsampling values (inclusive) for each dimension.pointsToInclude(PixelInCell include) Specifies the points of a given grid extent to include in the result.rounding(GridRoundingMode mode) Controls behavior of rounding from floating point values to integers.slice(DirectPosition slicePoint) Requests a grid geometry for a slice at the given "real world" position.sliceByRatio(double sliceRatio, int... dimensionsToKeep) Requests a grid geometry for a slice at the given relative position.subgrid(GridExtent areaOfInterest, int[] subsampling) Deprecated.Use the version withlongintegers instead ofint.subgrid(GridExtent areaOfInterest, long... subsampling) Requests a grid geometry over a sub-region of the base grid geometry and optionally with subsampling.subgrid(GridGeometry areaOfInterest) Adapts the base grid for the geographic area and resolution of the given grid geometry.Requests a grid geometry over a sub-envelope and optionally with a coarser resolution.Returns a string representation of thisGridDerivationfor debugging purpose.
- 
Field Details- 
baseThe base grid geometry from which to derive a new grid geometry.
 
- 
- 
Constructor Details- 
GridDerivationCreates a new builder for deriving a grid geometry from the specified base.- Parameters:
- base- the base to use as a template for deriving a new grid geometry.
- See Also:
 
 
- 
- 
Method Details- 
pointsToIncludeSpecifies the points of a given grid extent to include in the result. This information is used when a grid extent is specified in units different than the units of the base grid cells, which may happen withsubgrid(GridGeometry). In such case, the specified area of interest (AOI) needs to be transformed to the units of the base grid, and this property specifies what to include in the result:- With CELL_CENTER, the built extent contains the cell centers of the AOI.
- With CELL_CORNER, the built extent contains the cell corners of the AOI. It includes both lower and upper corners, thus covering the full cell areas.
 If this method is never invoked, the default value is PixelInCell.CELL_CORNER(built grid extent covering the full cell areas of the given AOI extent). If this method is invoked too late, anIllegalStateExceptionis thrown.- Parameters:
- include-- CELL_CENTERfor an extent containing cell centers, or- CELL_CORNERfor an extent containing all cell corners (i.e. full areas).
- Returns:
- thisfor method call chaining.
- Throws:
- IllegalStateException- if a- subgrid(…)or- slice(…)method has already been invoked.
- Since:
- 1.5
- See Also:
 
- With 
- 
roundingControls behavior of rounding from floating point values to integers. This setting modifies computations performed by the following methods (it has no effect on other methods in thisGridDerivationclass): If this method is never invoked, the default value isGridRoundingMode.NEAREST. If this method is invoked too late, anIllegalStateExceptionis thrown.- Parameters:
- mode- the new rounding mode.
- Returns:
- thisfor method call chaining.
- Throws:
- IllegalStateException- if a- subgrid(…)or- slice(…)method has already been invoked.
 
- 
clippingSpecifies whether to clip the derived grid extent to the extent of the base grid geometry. The default value isGridClippingMode.STRICT.- Parameters:
- mode- whether to clip the derived grid extent.
- Returns:
- thisfor method call chaining.
- Throws:
- IllegalStateException- if a- subgrid(…)or- slice(…)method has already been invoked.
- Since:
- 1.1
 
- 
marginSpecifies an number of cells by which to expandGridExtentafter rounding. This setting modifies computations performed by the following methods: For each dimension i of the grid computed by above methods, the low grid coordinate is subtracted bycellCount[i]and the high grid coordinate is increased bycellCount[i]. This calculation is done in units of the base grid cells, i.e. before subsampling. For example if subsampling is 2, then a margin of 6 cells specified with this method will result in a margin of 3 cells in the grid extent computed by thebuild()method.Use caseIf the caller wants to apply bilinear interpolations in an image, (s)he will need 1 more pixel on each image border. If the caller wants to apply bi-cubic interpolations, (s)he will need 2 more pixels on each image border.Default valuesIf this method is never invoked, the default value is zero for all dimensions. If this method is invoked too late, anIllegalStateExceptionis thrown. If thecellCountsarray length is shorter than the grid dimension, then zero is assumed for all missing dimensions.- Parameters:
- cellCounts- number of cells by which to expand the grid extent.
- Returns:
- thisfor method call chaining.
- Throws:
- IllegalArgumentException- if a value is negative.
- IllegalStateException- if a- subgrid(…)or- slice(…)method has already been invoked.
- See Also:
 
- 
chunkSizeSpecifies the size of tiles or chunks in the base grid geometry. If a chunk size is specified, then the grid extent computed bybuild()will span an integer number of chunks. The grid coordinates (0, 0, …) locate the corner of a chunk.This property operates on the same methods as the margin. If both a margin and a chunk size are specified, then margins are added first and the resulting grid coordinates are rounded to chunk size. This calculation is done in units of the base grid cells, i.e. before subsampling. For example if subsampling is 2, then a tile size of 20×20 pixels specified with this method will result in a tile size of 10×10 cells in the grid extent computed by the build()method.If this method is never invoked, the default value is one for all dimensions. If this method is invoked too late, an IllegalStateExceptionis thrown. If thecellCountsarray length is shorter than the grid dimension, then one is assumed for all missing dimensions.- Parameters:
- cellCounts- number of cells in all tiles or chunks.
- Returns:
- thisfor method call chaining.
- Throws:
- IllegalArgumentException- if a value is zero or negative.
- IllegalStateException- if a- subgrid(…)or- slice(…)method has already been invoked.
- Since:
- 1.1
 
- 
maximumSubsamplingSpecifies the maximum subsampling values (inclusive) for each dimension. If a subsampling value is greater than a specified value in the corresponding dimension, the subsampling will be clamped to the specified maximal value. Setting a maximum value of 1 in a dimension is equivalent to disabling subsampling in that dimension.If this method is never invoked, then there is no maximum value. If this method is invoked too late, an IllegalStateExceptionis thrown. If thecellCountsarray length is shorter than the grid dimension, then all missing dimensions have no maximum value.- Parameters:
- subsampling- maximal subsampling values (inclusive).
- Returns:
- thisfor method call chaining.
- Throws:
- IllegalArgumentException- if a value is zero or negative.
- IllegalStateException- if a- subgrid(…)or- slice(…)method has already been invoked.
- Since:
- 1.5
 
- 
maximumSubsamplingDeprecated.Use the version withlongintegers instead ofint. Small overviews of large images require large subsampling factors.Specifies the maximum subsampling values (32-bits version). SeemaximumSubsampling(long...)for details.- Parameters:
- subsampling- maximal subsampling values (inclusive).
- Returns:
- thisfor method call chaining.
- Since:
- 1.1
 
- 
subgridAdapts the base grid for the geographic area and resolution of the given grid geometry. By default, the new grid geometry will cover the intersection of the base grid geometry and the spatiotemporal region given byareaOfInterestenvelope. Whether that intersection is clipped can be configured. Coordinate operations are applied as needed if the Coordinate Reference Systems are not the same. The new grid geometry resolution will be integer multiples of the base grid geometry resolution.If gridExtentcontains only an envelope, then this method delegates tosubgrid(Envelope, double...). Otherwise, ifgridExtentcontains only an extent, then this method delegates tosubgrid(GridExtent, long...). Otherwise, the following information are mandatory:- Extent in areaOfInterest.
- Grid to CRS conversion in areaOfInterest.
- Grid to CRS conversion in basegrid.
 - Coordinate reference system in areaOfInterest.
- Coordinate reference system in basegrid.
- Extent in basegrid.
 UsageThis method can be helpful for implementation ofGridCoverageResource.read(GridGeometry, int...). Example:class MyDataStorage extends GridCoverageResource { @Override public GridCoverage read(GridGeometry domain, int... range) throws DataStoreException { GridDerivation change = getGridGeometry().derive().subgrid(domain); GridExtent toRead = change.buildExtent(); long[] subsampling = change.getSubsampling()); // Do reading here. } }Notes- This method can be invoked only once.
- This method cannot be used together with another subgrid(…)method.
- Rounding mode, clipping mode, margin and chunk size, if different than default values, should be set before to invoke this method.
- Slicing can be applied after this method.
- This method does not reduce the number of dimensions of the grid geometry.
       For dimensionality reduction, see GridGeometry.selectDimensions(int[]).
 - Parameters:
- areaOfInterest- the area of interest and desired resolution as a grid geometry.
- Returns:
- thisfor method call chaining.
- Throws:
- DisjointExtentException- if the given grid of interest does not intersect the grid extent.
- IncompleteGridGeometryException- if a mandatory property of a grid geometry is absent.
- IllegalGridGeometryException- if an error occurred while converting the envelope coordinates to grid coordinates.
- IllegalStateException- if a- subgrid(…)or- slice(…)method has already been invoked.
- See Also:
 
- Extent in 
- 
subgridRequests a grid geometry over a sub-envelope and optionally with a coarser resolution. The given envelope does not need to be expressed in the same coordinate reference system (CRS) than the CRS of the base grid geometry. Coordinate conversions or transformations will be applied as needed. That envelope CRS may have less dimensions than the CRS of the base grid geometry, in which case grid dimensions not mapped to envelope dimensions will be returned unchanged. The target resolution, if provided, shall be in same units and same order as the given envelope axes. If the length ofresolutionarray is less than the number of dimensions ofareaOfInterest, then no subsampling will be applied on the missing dimensions.Notes: - This method can be invoked only once.
- This method cannot be used together with another subgrid(…)method.
- Rounding mode, clipping mode, margin and chunk size, if different than default values, should be set before to invoke this method.
- Slicing can be applied after this method.
- This method does not reduce the number of dimensions of the grid geometry.
       For dimensionality reduction, see GridGeometry.selectDimensions(int[]).
- If the given envelope is known to be expressed in the same CRS as the grid geometry,
       then the CRS of the envelope
       can be left unspecified (null). It may give a slight performance improvement by avoiding the check for coordinate transformation.
- Subsampling computed by this method may be fractional. Consequently, calls to getSubsampling()andgetSubsamplingOffsets()after this method may cause anIllegalStateExceptionto be thrown.
 - Parameters:
- areaOfInterest- the desired spatiotemporal region in any CRS (transformations will be applied as needed), or- nullfor not restricting the sub-grid to a sub-area.
- resolution- the desired resolution in the same units and order than the axes of the given envelope, or- nullor an empty array if no subsampling is desired. The array length should be equal to the- areaOfInterestdimension, but this is not mandatory (zero or missing values mean no sub-sampling, extraneous values are ignored).
- Returns:
- thisfor method call chaining.
- Throws:
- DisjointExtentException- if the given area of interest does not intersect the grid extent.
- IncompleteGridGeometryException- if the base grid geometry has no extent, no "grid to CRS" transform, or no CRS (unless- areaOfInteresthas no CRS neither, in which case the CRS are assumed the same).
- IllegalGridGeometryException- if an error occurred while converting the envelope coordinates to grid coordinates.
- IllegalStateException- if a- subgrid(…)or- slice(…)method has already been invoked.
- See Also:
 
- 
subgridRequests a grid geometry over a sub-region of the base grid geometry and optionally with subsampling. The given grid geometry must have the same number of dimensions than the base grid geometry. If the length ofsubsamplingarray is less than the number of dimensions, then no subsampling will be applied on the missing dimensions.Notes: - This method can be invoked only once.
- This method cannot be used together with another subgrid(…)method.
- Rounding mode, clipping mode, margin and chunk size, if different than default values, should be set before to invoke this method.
- Slicing can be applied after this method.
- This method does not reduce the number of dimensions of the grid geometry.
       For dimensionality reduction, see GridGeometry.selectDimensions(int[]).
 - Parameters:
- areaOfInterest- the desired grid extent in units of base grid cells (i.e. ignoring subsampling), or- nullfor not restricting the sub-grid to a sub-area.
- subsampling- the subsampling to apply on each grid dimension, or- nullif none. All values shall be greater than zero. If the array length is shorter than the number of dimensions, missing values are assumed to be 1.
- Returns:
- thisfor method call chaining.
- Throws:
- DisjointExtentException- if the given area of interest does not intersect the grid extent.
- IncompleteGridGeometryException- if the base grid geometry has no extent, no "grid to CRS" transform, or no CRS (unless- areaOfInteresthas no CRS neither, in which case the CRS are assumed the same).
- IllegalStateException- if a- subgrid(…)or- slice(…)method has already been invoked.
- Since:
- 1.5
- See Also:
 
- 
subgrid@Deprecated(since="1.5") public GridDerivation subgrid(GridExtent areaOfInterest, int[] subsampling) Deprecated.Use the version withlongintegers instead ofint. Small overviews of large images require large subsampling factors.Requests a grid geometry over a sub-region (32-bits version). Seesubgrid(GridExtent, long...)for details.- Parameters:
- areaOfInterest- the desired grid extent in unit of base grid cell, or- null.
- subsampling- the subsampling to apply on each grid dimension, or- nullif none.
- Returns:
- thisfor method call chaining.
- Since:
- 1.1
 
- 
sliceRequests a grid geometry for a slice at the given "real world" position. The given position can be expressed in any coordinate reference system (CRS). The position should not define a coordinate for all dimensions, otherwise the slice would degenerate to a single point. Dimensions can be left unspecified either by assigning toslicePointa CRS without those dimensions, or by assigning the NaN value to some coordinates.ExampleIf the coordinate reference system of base grid geometry has (longitude, latitude, time) axes, then a (longitude, latitude) slice at time t can be created with one of the following two positions:- A three-dimensional position with (Double.NaN,Double.NaN, t) coordinates.
- A one-dimensional position with (t) coordinate and the coordinate reference system set to the temporal component of the grid geometry CRS.
 Usage notes- This method can be invoked after subgrid(Envelope, double...), but not before.
- If a non-default rounding mode is desired, it should be specified before to invoke this method.
- This method does not reduce the number of dimensions of the grid geometry.
       For dimensionality reduction, see GridGeometry.selectDimensions(int[]).
- If the given point is known to be expressed in the same CRS as the grid geometry,
       then the CRS of the point
       can be left unspecified (null). It may give a slight performance improvement by avoiding the check for coordinate transformation.
 - Parameters:
- slicePoint- the coordinates where to get a slice. If no coordinate reference system is associated, this method assumes that the slice point CRS is the CRS of the base grid geometry.
- Returns:
- thisfor method call chaining.
- Throws:
- IncompleteGridGeometryException- if the base grid geometry has no extent, no "grid to CRS" transform, or no CRS (unless- slicePointhas no CRS neither, in which case the CRS are assumed the same).
- IllegalGridGeometryException- if an error occurred while converting the point coordinates to grid coordinates.
- PointOutsideCoverageException- if the given point is outside the grid extent.
 
- A three-dimensional position with (
- 
sliceByRatioRequests a grid geometry for a slice at the given relative position. 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. The slicing is applied on all dimensions except the specified dimensions to keep.ExampleGiven a n-dimensional cube, the following call creates a slice of the two first dimensions (numbered 0 and 1, typically the dimensions of x and y axes) located at the center (ratio 0.5) of all other dimensions (typically z and/or t axes):gridGeometry.derive().sliceByRatio(0.5, 0, 1).build();- Parameters:
- sliceRatio- the ratio to apply on all grid dimensions except the ones to keep.
- dimensionsToKeep- the grid dimension to keep unchanged.
- Returns:
- thisfor method call chaining.
- Throws:
- IncompleteGridGeometryException- if the base grid geometry has no extent.
- IndexOutOfBoundsException- if a- dimensionsToKeepvalue is out of bounds.
 
- 
buildBuilds a grid geometry with the configuration specified by the other methods in thisGridDerivationclass.- Returns:
- the modified grid geometry. May be the basegrid geometry if no change apply.
- Throws:
- IllegalGridGeometryException- if the grid geometry cannot be computed because of arguments given to a- subgrid(…)or other methods.
- See Also:
 
- 
getIntersectionReturns the extent of the modified grid geometry, ignoring subsampling or changes in resolution. This is the intersection of thebasegrid geometry with the (grid or geospatial) envelope given to asubgrid(…)method, expanded by the specified margin (if any) and potentially with some grid sizes set to 1 if aslice(…)method has been invoked. The returned extent is in units of the base grid cells, (i.e. subsampling is ignored).This method can be invoked after build()for getting additional information. It can also be invoked withoutbuild()if only this information is desired.- Returns:
- intersection of grid geometry extents in units of basegrid cells.
- Throws:
- IncompleteGridGeometryException- if the base grid geometry has no extent.
 
- 
getGridTransformReturns the transform from derived grid coordinates to base grid coordinates. In the matrix representation of this transform, the scale factors on the diagonal are the subsampling values and the translation terms in the last column are the subsampling offsets.- Returns:
- transform of grid coordinates from the derived grid to the base grid.
- Since:
- 1.5
- See Also:
 
- 
hasSubsamplingpublic boolean hasSubsampling()Returns whether the conversion from the base grid to the derived grid contains a scale factor. A return value offalsemeans that all the following are true:- getSubsampling()returns an array filled with the value 1.
- getSubsamplingOffsets()returns an array filled with the value 0.
- getGridTransform(PixelInCell)returns an identity transform (regardless the argument).
 truemeans that the above are false, except the subsampling offsets which may still be zero.- Returns:
- whether the conversion from the base grid to the derived grid contains a scale factor.
- Since:
- 1.5
 
- 
getSubsamplingpublic long[] getSubsampling()Returns the strides for accessing cells along each axis of the base grid. Those values define part of the conversion from derived grid coordinates (x, y, z) to base grid coordinates (x′, y′, z′) as below (generalize to as many dimensions as needed):- x′ = s₀⋅x + t₀
- y′ = s₁⋅y + t₁
- z′ = s₂⋅z + t₂
 getSubsamplingOffsets()returns the {t₀, t₁, t₂} values. All subsampling values are strictly positive integers.This method can be invoked after build()for getting additional information. Ifsubgrid(GridExtent, long...)has been invoked, then this method returns the values that were given in thesubsamplingargument.Application to iterationsIteration overareaOfInterestgrid coordinates with a stride Δx=1 corresponds to an iteration inbasegrid coordinates with a stride of Δx′=s₀, a stride Δy=1 corresponds to a stride Δy′=s₁, etc.- Returns:
- an estimation of the strides for accessing cells along each axis of basegrid.
- Throws:
- IllegalStateException- if the subsampling factors are not integers. It may happen if the derived grid has been constructed by a call to- subgrid(Envelope, double...).
- Since:
- 1.1
- See Also:
 
- 
getSubsamplingOffsetspublic long[] getSubsamplingOffsets()Returns the offsets to be subtracted from pixel coordinates before subsampling. In a conversion from derived grid to base grid coordinates (the opposite direction of subsampling), the offset is the value to add after multiplication by the subsampling factor. It may be negative.This method can be invoked after build()for getting additional information.- Returns:
- conversion from the new grid to the original grid specified to the constructor.
- Throws:
- IllegalStateException- if the subsampling offsets are not integers. It may happen if the derived grid has been constructed by a call to- subgrid(Envelope, double...).
- Since:
- 1.1
- See Also:
 
- 
toStringReturns a string representation of thisGridDerivationfor debugging purpose. The returned string is implementation dependent and may change in any future version.
 
- 
longintegers instead ofint.