Class ConvertedGridCoverage


final class ConvertedGridCoverage extends DerivedGridCoverage
Decorates a GridCoverage in order to convert sample values on the fly. There is two strategies about when to convert sample values:
  • In calls to render(GridExtent), sample values are converted when first needed on a tile-by-tile basis then cached for future reuse. Note however that discarding the returned image may result in the lost of cached tiles.
  • In calls to BandedCoverage.Evaluator.apply(DirectPosition), the conversion is applied on-the-fly each time in order to avoid the potentially costly tile computations.
Since:
1.0
Version:
1.3
  • Field Details

    • converters

      private final org.opengis.referencing.operation.MathTransform1D[] converters
      Conversions from source values to converted values. The length of this array shall be equal to the number of bands.
    • isConverted

      private final boolean isConverted
      Whether this grid coverage is for converted values. If false, then this coverage is for packed values.
    • bandType

      private final DataType bandType
      One of enumeration value that describe the sample values type in each band of images produced by render(GridExtent). Shall not be null.
      See Also:
    • processor

      private final ImageProcessor processor
      The image processor to use for creating the tiles of converted values.
    • isUSerDefined

      private final boolean isUSerDefined
      true if the conversion was defined by user, or false if this instance has been created by forConvertedValues(boolean) implementation.
  • Constructor Details

    • ConvertedGridCoverage

      ConvertedGridCoverage(GridCoverage source, List<SampleDimension> range, org.opengis.referencing.operation.MathTransform1D[] converters, boolean isConverted, ImageProcessor processor, boolean isUSerDefined)
      Creates a new coverage with the same grid geometry than the given coverage but converted sample dimensions.
      Parameters:
      source - the coverage containing source values.
      range - the sample dimensions to assign to the converted grid coverage.
      converters - conversion from source to converted coverage, one transform per band.
      isConverted - whether this grid coverage is for converted or packed values.
      processor - the image processor to use for creating the tiles of converted values.
  • Method Details

    • create

      static GridCoverage create(GridCoverage source, boolean converted) throws org.opengis.referencing.operation.NoninvertibleTransformException
      Returns a coverage of converted values computed from a coverage of packed values, or conversely. If the given coverage is already converted, then this method returns coverage unchanged. This method is used for GridCoverage.forConvertedValues(boolean) default implementation.
      Parameters:
      source - the coverage containing values to convert.
      converted - true for a coverage containing converted values, or false for a coverage containing packed values.
      Returns:
      the converted coverage. May be source.
      Throws:
      org.opengis.referencing.operation.NoninvertibleTransformException - if this constructor cannot build a full conversion chain to target.
    • converters

      static org.opengis.referencing.operation.MathTransform1D[] converters(List<SampleDimension> sources, List<SampleDimension> targets, boolean converted) throws org.opengis.referencing.operation.NoninvertibleTransformException
      Returns the transforms for converting sample values from given sources to the converted status of those sources. This method opportunistically adds the target sample dimensions in target list.
      Parameters:
      sources - GridCoverage.getSampleDimensions() of source coverage.
      targets - where to add SampleDimension.forConvertedValues(boolean) results.
      converted - true for transforms to converted values, or false for transforms to packed values.
      Returns:
      the transforms, or null if all transforms are identity transform.
      Throws:
      org.opengis.referencing.operation.NoninvertibleTransformException - if this method cannot build a full conversion chain.
    • getBandType

      static DataType getBandType(List<SampleDimension> targets, boolean converted, GridCoverage source)
      Returns the data type for range of values of given sample dimensions. This data type applies to each band, not to a packed sample model (e.g. we assume no packing of 4 byte values in a single 32-bits integer).
      Parameters:
      targets - the sample dimensions for which to get the data type.
      converted - whether the image will hold converted or packed values.
      source - if the type cannot be determined, coverage from which to inherit the type as a fallback.
      Returns:
      the data type (never null).
      See Also:
    • getBandType

      final DataType getBandType()
      Returns the constant identifying the primitive type used for storing sample values.
      Overrides:
      getBandType in class DerivedGridCoverage
    • IsNotRepleacable

      final boolean IsNotRepleacable()
      Returns true if this coverage should not be replaced by its source.
      Overrides:
      IsNotRepleacable in class DerivedGridCoverage
      See Also:
    • evaluator

      public GridCoverage.Evaluator evaluator()
      Creates a new function for computing or interpolating sample values at given locations.

      Multi-threading

      Evaluators are not thread-safe. For computing sample values concurrently, a new GridCoverage.Evaluator instance should be created for each thread.
      Overrides:
      evaluator in class DerivedGridCoverage
      Returns:
      a new function for computing or interpolating sample values.
    • render

      public RenderedImage render(GridExtent sliceExtent)
      Creates a converted view over source data for the given extent. Values will be converted when first requested on a tile-by-tile basis. Note that if the returned image is discarded, then the cache of converted tiles will be discarded too.
      Specified by:
      render in class GridCoverage
      Parameters:
      sliceExtent - a subspace of this grid coverage extent where all dimensions except two have a size of 1 cell. May be null if this grid coverage has only two dimensions with a size greater than 1 cell.
      Returns:
      the grid slice as a rendered image with converted view.
    • forConvertedValues

      public GridCoverage forConvertedValues(boolean converted)
      Returns this coverage or the source coverage depending on whether converted matches the kind of content of this coverage.
      Overrides:
      forConvertedValues in class GridCoverage
      Parameters:
      converted - true for a coverage containing converted values, or false for a coverage containing packed values.
      Returns:
      a coverage containing converted or packed values, depending on converted argument value. May be this but never null.
      See Also:
    • createConvertedValues

      protected final GridCoverage createConvertedValues(boolean converted)
      Overridden as a matter of principle, but should not been invoked.
      Overrides:
      createConvertedValues in class GridCoverage
      Parameters:
      converted - true for a coverage containing converted values, or false for a coverage containing packed values.
      Returns:
      a new coverage containing converted or packed values, depending on converted argument value. May be this but never null.