Class ResampledGridCoverage


final class ResampledGridCoverage extends DerivedGridCoverage
A multi-dimensional grid coverage where each two-dimensional slice is the resampling of data from another grid coverage. This class is used when the resampling cannot be stored in a GridCoverage2D.
Since:
1.1
Version:
1.3
  • Field Details

    • BIDIMENSIONAL

      private static final int BIDIMENSIONAL
      The 2 constant for identifying code specific to the two-dimensional case.
      See Also:
    • toSourceCorner

      private final org.opengis.referencing.operation.MathTransform toSourceCorner
      The transform from cell coordinates in this coverage to cell coordinates in source coverage. Note that an offset may exist between cell coordinates and pixel coordinates, so some translations may need to be concatenated with this transform on an image-by-image basis.
    • toSourceCenter

      private final org.opengis.referencing.operation.MathTransform toSourceCenter
      The transform from cell coordinates in this coverage to cell coordinates in source coverage. Note that an offset may exist between cell coordinates and pixel coordinates, so some translations may need to be concatenated with this transform on an image-by-image basis.
    • toSourceDimensions

      private final long[] toSourceDimensions
      Mapping from dimensions in this ResampledGridCoverage to dimensions in the source coverage. The mapping is represented by a bitmask. For a target dimension i, toSourceDimensions[i] has a bit set to 1 for all source dimensions used in the computation of that target dimension. This array may be null if the mapping cannot be computed or if it is not needed.
    • imageProcessor

      private final ImageProcessor imageProcessor
      The image processor to use for resampling operations. Its configuration shall not be modified because this processor may be shared by different grid coverages.
    • supportSizeX

      private final int supportSizeX
      Value of Interpolation.getSupportSize(). This is 1 for nearest-neighbor, 2 for bilinear, 4 for bicubic interpolation.
    • supportSizeY

      private final int supportSizeY
      Value of Interpolation.getSupportSize(). This is 1 for nearest-neighbor, 2 for bilinear, 4 for bicubic interpolation.
  • Constructor Details

    • ResampledGridCoverage

      private ResampledGridCoverage(GridCoverage source, GridGeometry domain, org.opengis.referencing.operation.MathTransform toSourceCorner, org.opengis.referencing.operation.MathTransform toSourceCenter, CoordinateOperationFinder changeOfCRS, ImageProcessor processor)
      Creates a new grid coverage which will be the resampling of the given source.
      Parameters:
      source - the coverage to resample.
      domain - the grid extent, CRS and conversion from cell indices to CRS.
      toSourceCorner - transform from cell corner coordinates in this coverage to source coverage.
      toSourceCenter - transform from cell center coordinates in this coverage to source coverage.
      changeOfCRS - encapsulate information about the change of CRS.
      processor - the image processor to use for resampling images.
  • Method Details

    • findDependentDimensions

      private static long[] findDependentDimensions(org.opengis.referencing.operation.MathTransform mt, GridGeometry domain)
      Returns the set of target dimensions that depend on each source dimension. For a source dimension i, dependentDimensions[i] is a bitmask with bits set to 1 for each target dimension which require the source dimension i for its calculation.
      Parameters:
      mt - the transform (mapping pixel centers) for which to determine dimension dependencies.
      domain - domain of this .
      Returns:
      for each source dimension, a bitmask of target dependent dimensions. May be null if the mapping cannot be computed or if it is not needed.
    • getIntegerTranslation

      private static long[] getIntegerTranslation(org.opengis.referencing.operation.MathTransform toSource)
      If the given transform is a translation and all translation terms are integers, returns the translation. Otherwise returns null. It does not matter if the given transform is toSourceCenter or toSourceCorner, because those two transforms should be identical when all scale factors are 1. We nevertheless test the two transforms in case one of them has rounding errors.
    • specialize

      private GridCoverage specialize(boolean allowGeometryReplacement, boolean allowOperationReplacement) throws org.opengis.referencing.operation.TransformException
      If this coverage can be represented as a GridCoverage2D instance, returns such instance. Otherwise returns this.
      Parameters:
      allowGeometryReplacement - whether to allow the replacement of grid geometry in the target coverage.
      allowOperationReplacement - whether to allow the replacement of this operation by a more efficient one.
      Throws:
      org.opengis.referencing.operation.TransformException
    • equivalent

      static boolean equivalent(GridGeometry sourceGG, GridGeometry targetGG)
      Checks if two grid geometries are equal, ignoring unspecified properties. If a geometry has no extent or no gridToCRS transform, the missing property is not compared. Same applies for the grid extent.
      Returns:
      true if the two geometries are equal, ignoring unspecified properties.
    • isDefined

      private static boolean isDefined(GridGeometry sourceGG, GridGeometry targetGG, int property)
      Returns whether the given property is defined in both grid geometries.
      Parameters:
      property - one of GridGeometry constants.
    • create

      static GridCoverage create(GridCoverage source, GridGeometry target, ImageProcessor processor, boolean allowOperationReplacement) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException
      Implementation of GridCoverageProcessor.resample(GridCoverage, GridGeometry). This method computes the inverse of the transform from Source Grid to Target Grid. That transform will be computed using the following path:
      Target Grid ⟶ Target CRS ⟶ Source CRS ⟶ Source Grid
      If the target GridGeometry is incomplete, this method provides default values for the missing properties. The following cases may occur:
      • User provided no GridExtent. This method will construct a "grid to CRS" transform preserving (at least approximately) axis directions and resolutions at the point of interest. Then a grid extent will be created with a size large enough for containing the original grid transformed by above Source GridTarget Grid transform.
      • User provided only a GridExtent. This method will compute an envelope large enough for containing the projected coordinates, then a "grid to CRS" transform will be derived from the grid and the georeferenced envelope with an attempt to preserve axis directions at least approximately.
      • User provided only a "grid to CRS" transform. This method will transform the projected envelope to "grid units" using the specified transform and create a grid extent large enough to hold the result.
      Parameters:
      source - the grid coverage to resample.
      target - the desired geometry of returned grid coverage. May be incomplete.
      processor - the processor to use for executing the resample operation on images.
      allowOperationReplacement - whether to allow the replacement of this operation by a more efficient one.
      Returns:
      a grid coverage with the characteristics specified in the given grid geometry.
      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.
      org.opengis.util.FactoryException
    • targetExtent

      private static GridExtent targetExtent(GridExtent source, org.opengis.referencing.operation.MathTransform cornerToCRS, org.opengis.referencing.operation.MathTransform crsToGrid, boolean center) throws org.opengis.referencing.operation.TransformException
      Computes a target grid extent by transforming the source grid extent.
      Note on rounding mode: calculation of source envelope should use GridRoundingMode.ENCLOSING for making sure that we include all needed data. On the opposite, calculation of target envelope should use GridRoundingMode.CONTAINED for making sure that we interpolate only values where data are available. However, such "fully contained" mode is often overly strict because a very small rounding error can cause the lost of an image row or column, while using extrapolations for those values produce no perceptible errors. Consequently, this method uses GridRoundingMode.NEAREST as a compromise.
      Parameters:
      source - the source grid extent to transform.
      cornerToCRS - transform from source grid corners to target CRS.
      crsToGrid - transform from target CRS to target grid corners or centers.
      center - whether crsToGrid maps cell centers (true) or cell corners (false).
      Returns:
      target grid extent.
      Throws:
      org.opengis.referencing.operation.TransformException
    • render

      public RenderedImage render(GridExtent sliceExtent)
      Returns a two-dimensional slice of resampled grid data as a rendered image.
      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. Image location is relative to sliceExtent.
      Throws:
      CannotEvaluateException - if this method cannot produce the rendered image.