Class SliceGeometry

java.lang.Object
org.apache.sis.coverage.grid.SliceGeometry
All Implemented Interfaces:
Function<RenderedImage,GridGeometry>

final class SliceGeometry extends Object implements Function<RenderedImage,GridGeometry>
Builds a grid geometry for a slice in a GridCoverage. This is the implementation of GridGeometry.selectDimensions(int[]) and ImageRenderer.getImageGeometry(int) methods.

This class implements Function for allowing apply(…) to be invoked from outside this package. That function is invoked (indirectly) by TiledImage.getProperty(String).

Since:
1.1
Version:
1.3
  • Field Details

    • geometry

      private final GridGeometry geometry
      The coverage grid geometry from which to take a slice.
    • sliceExtent

      private final GridExtent sliceExtent
      Extents of the slice to take in the geometry.
    • gridDimensions

      private final int[] gridDimensions
      Dimensions of the slice to retain. All dimensions not in this sequence will be discarded. This is usually the array computed by GridExtent.getSubspaceDimensions(int).
    • factory

      private final org.opengis.referencing.operation.MathTransformFactory factory
      Factory to use for creating new transforms, or null for default.
  • Constructor Details

    • SliceGeometry

      SliceGeometry(GridGeometry geometry, GridExtent sliceExtent, int[] gridDimensions, org.opengis.referencing.operation.MathTransformFactory factory)
      Creates a new builder of slice geometry.
      Parameters:
      geometry - the grid geometry for which the transform is desired.
      sliceExtent - the requested extent, or null for the whole coverage.
      gridDimensions - the grid (not CRS) dimensions to select, in strictly increasing order.
  • Method Details

    • apply

      public GridGeometry apply(RenderedImage image)
      Computes the "org.apache.sis.GridGeometry" property value for the given image.
      Specified by:
      apply in interface Function<RenderedImage,GridGeometry>
      Parameters:
      image - the image for which to compute the image geometry.
      Throws:
      ImagingOpException - if the property cannot be computed.
    • reduce

      final GridGeometry reduce(GridExtent relativeExtent, int dimCRS) throws org.opengis.util.FactoryException
      Creates a new grid geometry over the specified dimensions of the geometry specified at construction time. The number of grid dimensions will be the length of the gridDimensions array, and the number of CRS dimensions will be reduced by the same amount.

      If a non-null sliceExtent has been specified, that extent shall be a sub-extent of the extent of the original grid geometry. In particular it must have the same number of dimensions in same order and the original "grid to CRS" transform shall be valid with that sliceExtent. That sub-extent will be used in replacement of the original extent for computing the geospatial area and the resolution.

      If a non-null relativeExtent is specified, a translation will be inserted before "grid to CRS" conversion in order that lowest coordinate values of sliceExtent (or original extent if there is no slice extent) will map to (0,0,…,0) coordinate values in relative extent. This is used for taking in account the translation between sliceExtent coordinates and coordinates of the image returned by GridCoverage.render(GridExtent), in which case the relative extent is the location and size of the RenderedImage. The number of dimensions of relative extent must be equal to gridDimensions array length (i.e. the dimensionality reduction must be already done).

      Parameters:
      relativeExtent - if non-null, an extent relative to sliceExtent to assign to the grid geometry to return. Dimensionality reduction shall be already applied.
      dimCRS - desired number of CRS dimensions, or -1 for automatic.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while separating the "grid to CRS" transform.
      See Also:
    • findTargetDimensions

      private static int[] findTargetDimensions(org.opengis.referencing.operation.MathTransform gridToCRS, GridExtent extent, double[] resolution, int[] gridDimensions, int dimCRS)
      Finds CRS (target) dimensions that are related to the given grid (source) dimensions. This method returns an array where the number of CRS dimensions has been reduced by the same amount than the reduction in number of grid dimensions.

      If this method is not invoked, then TransformSeparator will retain as many target dimensions as possible, which may be more than expected if a dimension that would normally be dropped is actually a constant (all scale coefficients set to zero). This method tries to avoid this effect by forcing the removal of CRS dimensions too. The CRS dimensions to remove are the ones that seem the less related to the grid dimensions that we keep. This method is not provided in TransformSeparator because of assumptions on the gridded nature of source coordinates.

      The algorithm used by this method (which is to compare the magnitude of scale coefficients anywhere in the matrix) assumes that grid cells are "square", e.g. that a translation of 1 pixel to the left is comparable in "real world" to a translation of 1 pixel to the bottom. This is often true but not always. To compensate, we divide scale coefficients by the GridGeometry.resolution for that CRS dimension.

      Parameters:
      gridToCRS - value of GridGeometry.gridToCRS (may be null).
      extent - value of GridGeometry.extent (may be null).
      resolution - value of GridGeometry.resolution (may be null).
      gridDimensions - the grid (source) dimensions to keep.
      dimCRS - desired number of CRS dimensions, or -1 for automatic.
      Returns:
      the CRS (target) dimensions to keep, or null if this method cannot compute them.
    • canNotCompute

      static ImagingOpException canNotCompute(org.opengis.util.FactoryException e)
      Invoked if an error occurred while computing the ImageRenderer.getImageGeometry(int) value. This exception should never occur actually, unless a custom factory implementation is used (instead of the Apache SIS default) and there is a problem with that factory.