Class DatumShiftGridLoader

java.lang.Object
org.apache.sis.internal.referencing.provider.DatumShiftGridLoader
Direct Known Subclasses:
NADCON.Loader, NTv2.Loader

class DatumShiftGridLoader extends Object
Base class of datum shift grid loaders.
Since:
0.7
Version:
1.1
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) final ByteBuffer
    The buffer to use for transferring data from the channel.
    private final ReadableByteChannel
    The channel opened on the file.
    private static final AtomicBoolean
    Whether the tip about the location of datum shift files has been logged.
    (package private) static final double
    Conversion factor from degrees to seconds.
    (package private) final Path
    The file to load, used for parameter declaration and if we have errors to report.
    (package private) static final double
    Possible precision for offset values in seconds of angle.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new loader for the given channel and an existing buffer.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static org.opengis.util.FactoryException
    canNotLoad(String format, Path file, Exception cause)
    Creates the exception to thrown when the provider failed to load the grid file.
    (package private) final void
    Makes sure that the buffer contains at least n remaining bytes.
    (package private) static void
    log(Class<?> caller, LogRecord record)
    Logs the given record.
    (package private) final void
    skip(int n)
    Skips exactly n bytes.
    (package private) static void
    startLoading(Class<?> caller, Object file)
    Logs a message about a grid which is about to be loaded.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEGREES_TO_SECONDS

      static final double DEGREES_TO_SECONDS
      Conversion factor from degrees to seconds.
      See Also:
    • SECOND_PRECISION

      static final double SECOND_PRECISION
      Possible precision for offset values in seconds of angle. This value is used only as a hint when attempting to compress the grid in arrays of short values. It does not hurt if this value is wrong, as it will only cause the grid to not be compressed.

      Some interesting values:

      • 1E-4 is about 3 millimetres on Earth.
      • 1E-6 matches the precision found in ASCII outputs of NADCON grids.
      • 1E-7 is about 1 ULP of 1 second of angle.
      We use a value of 1E-4 because more accurate values tend to cause overflows in the compression algorithm, in which case the compression fails. With a more reasonable value, we have better chances of success.
      See Also:
    • file

      final Path file
      The file to load, used for parameter declaration and if we have errors to report.
    • channel

      private final ReadableByteChannel channel
      The channel opened on the file.
    • buffer

      final ByteBuffer buffer
      The buffer to use for transferring data from the channel.
    • datumDirectoryLogged

      private static final AtomicBoolean datumDirectoryLogged
      Whether the tip about the location of datum shift files has been logged. We log this tip only once, and only if we failed to load at least one grid.
  • Constructor Details

    • DatumShiftGridLoader

      DatumShiftGridLoader(ReadableByteChannel channel, ByteBuffer buffer, Path file) throws IOException
      Creates a new loader for the given channel and an existing buffer.
      Parameters:
      channel - where to read data from.
      buffer - the buffer to use.
      file - path to the longitude or latitude difference file. Used for parameter declaration and error reporting.
      Throws:
      IOException
  • Method Details

    • ensureBufferContains

      final void ensureBufferContains(int n) throws IOException
      Makes sure that the buffer contains at least n remaining bytes. It is caller's responsibility to ensure that the given number of bytes is not greater than the buffer capacity.
      Parameters:
      n - the minimal number of bytes needed in the buffer.
      Throws:
      EOFException - if the channel has reached the end of stream.
      IOException - if another kind of error occurred while reading.
    • skip

      final void skip(int n) throws IOException
      Skips exactly n bytes.
      Throws:
      IOException
    • startLoading

      static void startLoading(Class<?> caller, Object file)
      Logs a message about a grid which is about to be loaded.
      Parameters:
      caller - the provider to logs as the source class. the source method will be set to "createMathTransform".
      file - the grid file, as a String or a Path.
    • log

      static void log(Class<?> caller, LogRecord record)
      Logs the given record.
      Parameters:
      caller - the provider to logs as the source class. the source method will be set to "createMathTransform".
      record - the record to log.
    • canNotLoad

      static org.opengis.util.FactoryException canNotLoad(String format, Path file, Exception cause)
      Creates the exception to thrown when the provider failed to load the grid file.
      Parameters:
      format - the format name (e.g. "NTv2" or "NADCON").
      file - the grid file that the subclass tried to load.
      cause - the cause of the failure to load the grid file.