Class GridCoverageProcessor

Object
GridCoverageProcessor
All Implemented Interfaces:
Cloneable

public class GridCoverageProcessor extends Object implements Cloneable
A predefined set of operations on grid coverages. After instantiation, Grid­Coverage­Processor can be configured for the following aspects: For each coverage operations, above properties are combined with parameters given to the operation method.

Thread-safety

Grid­Coverage­Processor is safe for concurrent use in multi-threading environment.
Since:
1.1
See Also:
  • Field Details

  • Constructor Details

    • GridCoverageProcessor

      public GridCoverageProcessor()
      Creates a new processor with default configuration.
    • GridCoverageProcessor

      public GridCoverageProcessor(ImageProcessor processor)
      Creates a new processor initialized to the given configuration.
      Parameters:
      processor - the processor to use for operations on two-dimensional slices.
  • Method Details

    • getInterpolation

      public Interpolation 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

      public void setInterpolation(Interpolation method)
      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

      public Number[] 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

      public void setFillValues(Number... values)
      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, or null for the defaults.
      Since:
      1.2
      See Also:
    • getColorizer

      public Colorizer 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

      public void setColorizer(Colorizer colorizer)
      Sets the colorization algorithm to apply on computed images. The colorizer is used by convert(…) and aggregate­Ranges(…) operations among others. The default implementation delegates to the image processor.
      Parameters:
      colorizer - colorization algorithm to apply on computed image, or null for default.
      Since:
      1.4
      See Also:
    • getPositionalAccuracyHints

      public 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(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 a null array if none. Null elements in the array are ignored.
      See Also:
    • getOptimizations

      public Set<GridCoverageProcessor.Optimization> 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

      public void setOptimizations(Set<GridCoverageProcessor.Optimization> enabled)
      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). If mask­Inside is true, then all pixels inside the given ROI are set to the fill values. If mask­Inside is false, 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.
      mask­Inside - true for masking pixels inside the shape, or false for masking outside.
      Returns:
      a coverage with mask applied.
      Throws:
      Transform­Exception - 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 the converters array, which must be greater than 0 and not greater than the number of sample dimensions in the source coverage. If the converters 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-null sample­Dimension­Modifier function. If non-null, that function will be invoked with, as input, a pre-configured sample dimension builder. The sample­Dimension­Modifier function can change the sample dimension name or rebuild the categories.

      Result relationship with source

      If the source coverage is backed by a Writable­Rendered­Image, 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.
      sample­Dimension­Modifier - a callback for modifying the Sample­Dimension​.Builder default configuration for each sample dimension of the target coverage, or null if none.
      Returns:
      the coverage which computes converted values from the given source.
      Since:
      1.3
      See Also:
    • shiftGrid

      public GridCoverage shiftGrid(GridCoverage source, long... translation)
      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

      The translation 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:

      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:
      Arithmetic­Exception - 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 TransformException
      Creates a new coverage with a different grid extent, resolution or coordinate reference system. The desired properties are specified by the Grid­Geometry 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.
      The interpolation method can be specified by set­Interpolation(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:

      Properties used

      This operation uses the following properties in addition to method parameters:
      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:
      Incomplete­Grid­Geometry­Exception - if the source grid geometry is missing an information. It may be the source CRS, the source extent, etc. depending on context.
      Transform­Exception - 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(Grid­Coverage, Grid­Geometry) 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:
      Incomplete­Grid­Geometry­Exception - if the source grid geometry is missing an information.
      Transform­Exception - if some coordinates cannot be transformed to the specified target.
      Since:
      1.3
    • reduceDimensionality

      public GridCoverage reduceDimensionality(GridCoverage source)
      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

      public GridCoverage removeGridDimensions(GridCoverage source, int... gridAxesToRemove)
      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 an Illegal­Grid­Geometry­Exception.

      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 Subspace­Not­Specified­Exception. If desired, this restriction can be relaxed by direct use of Dimensionality­Reduction 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);
      
      Alternatively the with­Slice­Point(…) 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.
      grid­Axes­To­Remove - 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:
      Index­Out­Of­Bounds­Exception - if a grid axis index is out of bounds.
      Subspace­Not­Specified­Exception - if at least one removed dimension has a grid extent size larger than 1 cell.
      Illegal­Grid­Geometry­Exception - if the dimensions to keep cannot be separated from the dimensions to omit.
      Since:
      1.4
      See Also:
    • selectGridDimensions

      public GridCoverage selectGridDimensions(GridCoverage source, int... gridAxesToPass)
      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 the grid­Axes­To­Pass 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 the grid­Axes­To­Pass array, then this method will throw an Illegal­Grid­Geometry­Exception.

      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 Subspace­Not­Specified­Exception. If desired, this restriction can be relaxed by direct use of Dimensionality­Reduction 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);
      
      Alternatively the with­Slice­Point(…) 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.
      grid­Axes­To­Pass - 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:
      Index­Out­Of­Bounds­Exception - if a grid axis index is out of bounds.
      Subspace­Not­Specified­Exception - if at least one removed dimension has a grid extent size larger than 1 cell.
      Illegal­Grid­Geometry­Exception - if the dimensions to keep cannot be separated from the dimensions to omit.
      Since:
      1.4
      See Also:
    • selectSampleDimensions

      public GridCoverage selectSampleDimensions(GridCoverage source, int... bands)
      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 specified bands indices select all sample dimensions in the same order, then source 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:
      Illegal­Argument­Exception - if a sample dimension index is invalid.
      Since:
      1.4
      See Also:
    • aggregateRanges

      public GridCoverage aggregateRanges(GridCoverage... sources)
      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 aggregate­Ranges(Grid­Coverage[], 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:
      Illegal­Grid­Geometry­Exception - if a grid geometry is not compatible with the others.
      Since:
      1.4
      See Also:
    • aggregateRanges

      public GridCoverage aggregateRanges(GridCoverage[] sources, int[][] bandsPerSource)
      Aggregates in a single coverage the specified bands of a sequence of source coverages, in order. This method performs the same work than aggregate­Ranges(Grid­Coverage...), but with the possibility to specify the sample dimensions to retain in each source coverage. The bands­Per­Source argument specifies the sample dimensions to keep, in order. That array can be null for selecting all sample dimensions in all source coverages, or may contain null 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.
      Some of those restrictions may be relaxed in future Apache SIS versions.
      Parameters:
      sources - coverages whose bands shall be aggregated, in order. At least one coverage must be provided.
      bands­Per­Source - bands to use for each source coverage, in order. May contain null elements.
      Returns:
      the aggregated coverage, or one of the sources if it can be used directly.
      Throws:
      Illegal­Grid­Geometry­Exception - if a grid geometry is not compatible with the others.
      Illegal­Argument­Exception - if some band indices are duplicated or outside their range of validity.
      Since:
      1.4
      See Also:
    • visualize

      public RenderedImage visualize(GridCoverage source, GridExtent slice)
      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 the Colorizer 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, or null for the whole coverage.
      Returns:
      rendered image for visualization purposes only.
      Throws:
      Illegal­Argument­Exception - 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

      public boolean equals(Object object)
      Returns true if the given object is a coverage processor of the same class with the same configuration.
      Overrides:
      equals in class Object
      Parameters:
      object - the other object to compare with this processor.
      Returns:
      whether the other 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.
      Overrides:
      hash­Code in class Object
      Returns:
      a hash code value for this processor.
    • clone

      public GridCoverageProcessor clone()
      Returns a coverage processor with the same configuration than this processor.
      Overrides:
      clone in class Object
      Returns:
      a clone of this coverage processor.