Class GridCoverageProcessor

java.lang.Object
org.apache.sis.coverage.grid.GridCoverageProcessor
All Implemented Interfaces:
Cloneable

public class GridCoverageProcessor extends Object implements 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:
  • 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

    • unique

      static ImageProcessor unique(ImageProcessor image)
      Returns an unique instance of the given processor. Both the given and the returned processors shall be unmodified, because they may be shared by many GridCoverage instances.
    • 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:
    • 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 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
    • 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:
    • 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). If maskInside is true, then all pixels inside the given ROI are set to the fill values. If maskInside is false, 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, or false 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 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 sampleDimensionModifier function. If non-null, that function will be invoked with, as input, a pre-configured sample dimension builder. The sampleDimensionModifier function can change the sample dimension name or rebuild the categories.

      Result relationship with source

      If the source coverage is backed by a WritableRenderedImage, 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 the SampleDimension.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:
      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 the GridGeometry 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 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:
      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

      static void recoverableException(String caller, Exception ex)
      Invoked when an ignorable exception occurred.
      Parameters:
      caller - the method where the exception occurred.
      ex - the ignorable exception.
    • 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:
      hashCode 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.