Class NADCON.Loader

java.lang.Object
org.apache.sis.internal.referencing.provider.DatumShiftGridLoader
org.apache.sis.internal.referencing.provider.NADCON.Loader
Enclosing class:
NADCON

private static final class NADCON.Loader extends DatumShiftGridLoader
Loaders of NADCON data. Instances of this class exist only at loading time. This class can read both binary and ASCII grid files.

Binary format

NADCON binary files ("*.las" and "*.los") are organized into records with the first record containing the header information, followed by the shift data. The length of each record (including header) depends on the number of columns.

Records are ordered from South to North. Each record (except the header) is an entire row of grid points, with values ordered from West to East. Each value is a float encoded in little endian byte order. Each record ends with a 4 byte separator.

Record data use a different convention than the record header. The header uses degrees of angle with positive values East. But the offset values after the header are in seconds of angle with positive values West. The DatumShiftGrid returned by this loader uses the header convention, which also matches the order in which offset values appear in each row.

Since:
0.7
Version:
0.7
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final StringBuilder
    Temporary buffer for ASCII characters, or null if the file is a binary file.
    private static final int
    The length of the description in the header, in bytes.
    (package private) DatumShiftGridFile.Float<javax.measure.quantity.Angle,javax.measure.quantity.Angle>
    private static final String
    The first bytes that we expect to find the header (both binary and ASCII files).
    private final int
    Number of longitude (nx) and latitude (ny) values.
    private final int
    Number of longitude (nx) and latitude (ny) values.
    private final int
    Number of longitude (nx) and latitude (ny) values.
    private final float
    Longitude and latitude of of the first value in the first record, in degrees.
    private final float
    Longitude and latitude of of the first value in the first record, in degrees.
    private final float
    The difference between longitude (Δx) and latitude (Δy) cells, in degrees.
    private final float
    The difference between longitude (Δx) and latitude (Δy) cells, in degrees.

    Fields inherited from class org.apache.sis.internal.referencing.provider.DatumShiftGridLoader

    buffer, DEGREES_TO_SECONDS, file, SECOND_PRECISION
  • Constructor Summary

    Constructors
    Constructor
    Description
    Loader(ReadableByteChannel channel, ByteBuffer buffer, Path file)
    Creates a new reader for the given channel.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Invoked when the given FloatBuffer buffer is empty.
    private static boolean
    Returns true if all remaining characters in the buffer are US-ASCII characters for real numbers, except the characters on the first line which may be any printable US-ASCII characters.
    private String
    Returns the next word from an ASCII file.
    (package private) final void
    readGrid(FloatBuffer fb, NADCON.Loader latitudeShifts, Path longitudeShifts)
    Loads latitude or longitude shifts data.
    private void
    Sets the position and limit of the given FloatBuffer to the same position and limit than the underlying ByteBuffer, converted to units of float data type.
    private org.opengis.util.FactoryException
    Returns the exception to thrown in the file does not seems to be a NADCON format.

    Methods inherited from class org.apache.sis.internal.referencing.provider.DatumShiftGridLoader

    canNotLoad, ensureBufferContains, log, skip, startLoading

    Methods inherited from class java.lang.Object

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

    • DESCRIPTION_LENGTH

      private static final int DESCRIPTION_LENGTH
      The length of the description in the header, in bytes.
      • 56 bytes of NADCON's identification: "NADCON EXTRACTED REGION".
      • 8 bytes of "PGM" (unknown meaning).
      See Also:
    • NADCON

      private static final String NADCON
      The first bytes that we expect to find the header (both binary and ASCII files). We use that as the format signature.
      See Also:
    • x0

      private final float x0
      Longitude and latitude of of the first value in the first record, in degrees.
    • y0

      private final float y0
      Longitude and latitude of of the first value in the first record, in degrees.
    • Δx

      private final float Δx
      The difference between longitude (Δx) and latitude (Δy) cells, in degrees.
    • Δy

      private final float Δy
      The difference between longitude (Δx) and latitude (Δy) cells, in degrees.
    • nx

      private final int nx
      Number of longitude (nx) and latitude (ny) values.
    • ny

      private final int ny
      Number of longitude (nx) and latitude (ny) values.
    • nz

      private final int nz
      Number of longitude (nx) and latitude (ny) values.
    • ascii

      private final StringBuilder ascii
      Temporary buffer for ASCII characters, or null if the file is a binary file.
    • grid

      DatumShiftGridFile.Float<javax.measure.quantity.Angle,javax.measure.quantity.Angle> grid
  • Constructor Details

    • Loader

      Loader(ReadableByteChannel channel, ByteBuffer buffer, Path file) throws IOException, org.opengis.util.FactoryException
      Creates a new reader for the given channel. The file can be binary or ASCII. This constructor parses the header immediately, but does not read any grid.
      Parameters:
      channel - where to read data from.
      buffer - the buffer to use. That buffer must use little endian byte order and have a capacity divisible by the size of the float type.
      file - path to the longitude or latitude difference file. Used for parameter declaration and error reporting.
      Throws:
      IOException
      org.opengis.util.FactoryException
  • Method Details

    • isASCII

      private static boolean isASCII(ByteBuffer buffer)
      Returns true if all remaining characters in the buffer are US-ASCII characters for real numbers, except the characters on the first line which may be any printable US-ASCII characters. If the content is assumed ASCII, then the buffer position is set to the first EOL character.
      Returns:
      true if the file seems to be an ASCII one.
    • nextWord

      private String nextWord() throws IOException
      Returns the next word from an ASCII file. This method is invoked only for parsing ASCII files, in which case the ascii string builder is non-null.
      Throws:
      IOException
    • unexpectedFormat

      private org.opengis.util.FactoryException unexpectedFormat()
      Returns the exception to thrown in the file does not seems to be a NADCON format.
    • readGrid

      final void readGrid(FloatBuffer fb, NADCON.Loader latitudeShifts, Path longitudeShifts) throws IOException, org.opengis.util.FactoryException, org.opengis.referencing.operation.NoninvertibleTransformException
      Loads latitude or longitude shifts data. This method should be invoked twice:
      1. On an instance created for the latitude shifts file with a latitude argument set to null.
      2. On an instance created for the longitude shifts file with a latitude argument set to the instance created in the previous step.
      The result is stored in the grid field.
      Parameters:
      fb - a FloatBuffer view over the full DatumShiftGridLoader.buffer range.
      latitudeShifts - the previously loaded latitude shifts, or null if not yet loaded.
      longitudeShifts - the file for the longitude grid.
      Throws:
      IOException
      org.opengis.util.FactoryException
      org.opengis.referencing.operation.NoninvertibleTransformException
    • fillBuffer

      private void fillBuffer(FloatBuffer fb) throws IOException
      Invoked when the given FloatBuffer buffer is empty. This method requests one float from the channel, but the channel will usually give us as many data as the buffer can contain.
      Throws:
      IOException
    • syncView

      private void syncView(FloatBuffer fb)
      Sets the position and limit of the given FloatBuffer to the same position and limit than the underlying ByteBuffer, converted to units of float data type.