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

java.lang.Object
org.apache.sis.referencing.datum.DatumShiftGrid<C,T>
org.apache.sis.internal.referencing.provider.DatumShiftGridFile<C,T>
org.apache.sis.internal.referencing.provider.DatumShiftGridCompressed<C,T>
Type Parameters:
C - dimension of the coordinate unit (usually Angle).
T - dimension of the translation unit (usually Angle or Length).
All Implemented Interfaces:
Serializable

final class DatumShiftGridCompressed<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>> extends DatumShiftGridFile<C,T>
A datum shift grid which store the values in short[] array. In addition to using half the space of float[] arrays, it can also (ironically) increase the precision in the common case where the shifts are specified with no more than 5 digits in base 10 in ASCII files.
Since:
0.7
Version:
1.1
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serial number for inter-operability with different versions.
      See Also:
    • averages

      private final double[] averages
      An "average" value for the offset in each dimension.
      See Also:
    • data

      private final short[][] data
      Differences between averages values and the actual value. The differences need to be multiplied by scale.
    • scale

      private final double scale
      The factor by which to multiply each data value before to add to the averages.
  • Constructor Details

    • DatumShiftGridCompressed

      private DatumShiftGridCompressed(DatumShiftGridFile<C,T> grid, double[] averages, short[][] data, double scale)
      Creates a new datum shift grid for the same geometry than the given grid but different data.
  • Method Details

    • compress

      static <C extends javax.measure.Quantity<C>, T extends javax.measure.Quantity<T>> DatumShiftGridFile<C,T> compress(DatumShiftGridFile.Float<C,T> grid, double[] averages, double scale)
      Tries to compress the given grid. If this operation succeed, a new grid is returned. Otherwise this method returns the given grid unchanged.
      Parameters:
      grid - the grid to compress.
      averages - an "average" value for the offset in each dimension, or null if unknown.
      scale - the factor by which to multiply each compressed value before to add to the average value.
      Returns:
      the grid to use (may or may not be compressed).
    • 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.
    • getCellPrecision

      public double getCellPrecision()
      Suggests a precision for the translation values in this grid.
      Overrides:
      getCellPrecision in class DatumShiftGridFile<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>>
      Returns:
      a precision for the translation values in this grid.
    • getData

      protected final Object[] getData()
      Returns direct references (not cloned) to the data arrays. This method is for cache management, equals(Object) and 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 final int getTranslationDimensions()
      Returns the number of shift 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.
    • getCellMean

      public double getCellMean(int dim)
      Returns the average translation parameters from source to target.
      Overrides:
      getCellMean in class DatumShiftGrid<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>>
      Parameters:
      dim - the dimension for which to get an average value.
      Returns:
      a value close to the average for the given dimension.
    • getCellValue

      public double getCellValue(int dim, int gridX, int gridY)
      Returns the cell value at the given grid index.
      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, from 0 inclusive to DatumShiftGrid.getTranslationDimensions() exclusive.
      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)
      Copy of DatumShiftGrid rewritten in a way that reduce the number of arithmetic operations for efficiency reasons.
      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:
    • equals

      public boolean equals(Object other)
      Returns true if the given object is a grid containing the same data than this grid.
      Overrides:
      equals in class DatumShiftGridFile<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>>
      Parameters:
      other - the other object to compare with this datum shift grid.
      Returns:
      true if the given object is non-null, an instance of DatumShiftGridCompressed and contains the same data.
    • hashCode

      public int hashCode()
      Returns a hash code value for this datum shift grid.
      Overrides:
      hashCode in class DatumShiftGridFile<C extends javax.measure.Quantity<C>,T extends javax.measure.Quantity<T>>
      Returns:
      a hash code based on metadata.