Class DatumShiftGridGroup<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>>

All Implemented Interfaces:
Serializable

final class DatumShiftGridGroup<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>> extends DatumShiftGridFile<C,T>
A group of datum shift grids. This is used when a NTv2 file contains more than one grid with no common parent. This class creates a synthetic parent which always delegates its work to a child (as opposed to more classical transform trees where the parent can do some work if no child can). Coordinate transformations will be applied as below:
  1. SpecializableTransform will try to locate the most appropriate grid for given coordinates. This is the class where to put our optimization efforts, for example by checking the last used grid before to check all other grids.
  2. Only if SpecializableTransform did not found a better transform, it will fallback on a transform backed by this DatumShiftGridGroup. In such case, InterpolatedTransform will perform its calculation by invoking interpolateInCell(double, double, double[]). That method tries again to locate the best grid, but performance is less important there since that method is only a fallback.
  3. The default DatumShiftGrid.interpolateInCell(double, double, double[]) implementation invokes getCellValue(int, int, int). We provide that method for consistency, but it should not be invoked since we overrode interpolateInCell(double, double, double[]).
Since:
1.1
Version:
1.1
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • regions

      private final DatumShiftGridGroup.Region[] regions
      For each subgrids[i], regions[i] is the range of indices valid for that grid. This array will be used only as a fallback if SpecializableTransform has not been able to find the sub-grid itself. Since it should be rarely used, we do not bother using a R-Tree.
  • Constructor Details

    • DatumShiftGridGroup

      private DatumShiftGridGroup(Tile[] tiles, Map<Tile,DatumShiftGridFile<C,T>> grids, AffineTransform2D gridToCRS, Dimension gridSize) throws IOException, org.opengis.referencing.operation.NoninvertibleTransformException
      Creates a new group for the given list of sub-grids. That list shall contain at least 2 elements. The first sub-grid is taken as a template for setting parameter values such as filename (all list elements should declare the same filename parameters, so the selected element should not matter).
      Parameters:
      tiles - the tiles computed by TileOrganizer.
      grids - sub-grids associated to tiles computed by TileOrganizer.
      gridToCRS - conversion from grid indices to "real world" coordinates.
      gridSize - number of cells along the x and y axes in the grid.
      Throws:
      IOException - declared because Tile.getRegion() declares it, but should not happen.
      org.opengis.referencing.operation.NoninvertibleTransformException
    • DatumShiftGridGroup

      private DatumShiftGridGroup(DatumShiftGridGroup<C,T> other, DatumShiftGridFile<C,T>[] data)
      Creates a new grid sharing the same data than an existing grid. This constructor is for setData(Object[]) usage only.
  • Method Details

    • create

      static <C extends javax.measure.Quantity<C>, T extends javax.measure.Quantity<T>> DatumShiftGridGroup<C,T> create(Path file, List<DatumShiftGridFile<C,T>> subgrids) throws IOException, org.opengis.util.FactoryException, org.opengis.referencing.operation.NoninvertibleTransformException
      Puts the given sub-grid in a group. This method infers itself what would be the size of a grid containing all given sub-grids.
      Parameters:
      file - filename to report in case of error.
      subgrids - the sub-grids to put under a common root.
      Throws:
      org.opengis.util.FactoryException - if the sub-grid cannot be combined in a single mosaic or pyramid.
      IOException - declared because Tile.getRegion() declares it, but should not happen.
      org.opengis.referencing.operation.NoninvertibleTransformException
    • setData

      protected final DatumShiftGridFile<C,T> setData(Object[] other)
      Returns a new grid with the same geometry than this grid but different data arrays. This method is invoked by DatumShiftGridFile.useSharedData() when it detects that a newly created grid uses the same data than an existing grid. The other object is the old grid, so we can share existing data.
      Specified by:
      setData in class DatumShiftGridFile<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>>
      Parameters:
      other - data from another DatumShiftGridFile that we can share.
      Returns:
      a new DatumShiftGridFile using the given data reference.
    • getData

      protected Object[] getData()
      Returns direct references (not cloned) to the data arrays. This method is for cache management, DatumShiftGridFile.equals(Object) and DatumShiftGridFile.hashCode() implementations only and should not be invoked in other context.
      Specified by:
      getData in class DatumShiftGridFile<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>>
      Returns:
      a direct (not cloned) reference to the internal data array.
    • getTranslationDimensions

      public int getTranslationDimensions()
      Returns the number of dimensions of the translation vectors interpolated by this datum shift grid. This implementation takes the first sub-grid as a template. The choice of the grid does not matter since all grids have the same number of target dimensions.
      Specified by:
      getTranslationDimensions in class DatumShiftGrid<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>>
      Returns:
      number of dimensions of translation vectors.
    • getCellValue

      public double getCellValue(int dim, int gridX, int gridY)
      Returns the translation stored at the given two-dimensional grid indices for the given dimension. This method is defined for consistency with interpolateInCell(double, double, double[]) but should never be invoked. The InterpolatedTransform class will rather invoke the interpolateInCell(…) method for efficiency.

      Caller must ensure that all arguments given to this method are in their expected ranges. The behavior of this method is undefined if any argument value is out-of-range.

      Specified by:
      getCellValue in class DatumShiftGrid<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>>
      Parameters:
      dim - the dimension of the translation vector component to get.
      gridX - the grid index on the x axis, from 0 inclusive to gridSize[0] exclusive.
      gridY - the grid index on the y axis, from 0 inclusive to gridSize[1] exclusive.
      Returns:
      the translation for the given dimension in the grid cell at the given index.
    • interpolateInCell

      public void interpolateInCell(double gridX, double gridY, double[] vector)
      Interpolates the translation to apply for the given two-dimensional grid indices. During forward coordinate transformations, this method is invoked only if SpecializableTransform has been unable to use directly one of the child transforms — so performance is not the priority in that situation. During inverse transformations, this method is invoked for estimating an initial position before iterative refinements. The given point may be outside all sub-grids (otherwise SpecializableTransform would have done the work itself at least in the forward transformation case). Consequently, searching a sub-grid containing the given point is not sufficient; we need to search for the nearest grid even if the point is outside.
      Overrides:
      interpolateInCell in class DatumShiftGrid<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>>
      Parameters:
      gridX - first grid coordinate of the point for which to get the translation.
      gridY - second grid coordinate of the point for which to get the translation.
      vector - a pre-allocated array where to write the translation vector.
      See Also: