Class NADCON.Loader
java.lang.Object
org.apache.sis.internal.referencing.provider.DatumShiftGridLoader
org.apache.sis.internal.referencing.provider.NADCON.Loader
- Enclosing class:
- NADCON
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
FieldsModifier and TypeFieldDescriptionprivate final StringBuilder
Temporary buffer for ASCII characters, ornull
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> The grid created byreadGrid(FloatBuffer, Loader, Path)
.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
ConstructorsConstructorDescriptionLoader
(ReadableByteChannel channel, ByteBuffer buffer, Path file) Creates a new reader for the given channel. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Invoked when the givenFloatBuffer
buffer is empty.private static boolean
isASCII
(ByteBuffer buffer) Returnstrue
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
nextWord()
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
syncView
(FloatBuffer fb) Sets the position and limit of the givenFloatBuffer
to the same position and limit than the underlyingByteBuffer
, converted to units offloat
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
-
Field Details
-
DESCRIPTION_LENGTH
private static final int DESCRIPTION_LENGTHThe 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:
- 56 bytes of NADCON's identification:
-
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 x0Longitude and latitude of of the first value in the first record, in degrees. -
y0
private final float y0Longitude and latitude of of the first value in the first record, in degrees. -
Δx
private final float ΔxThe difference between longitude (Δx) and latitude (Δy) cells, in degrees. -
Δy
private final float ΔyThe difference between longitude (Δx) and latitude (Δy) cells, in degrees. -
nx
private final int nxNumber of longitude (nx) and latitude (ny) values. -
ny
private final int nyNumber of longitude (nx) and latitude (ny) values. -
nz
private final int nzNumber of longitude (nx) and latitude (ny) values. -
ascii
Temporary buffer for ASCII characters, ornull
if the file is a binary file. -
grid
DatumShiftGridFile.Float<javax.measure.quantity.Angle,javax.measure.quantity.Angle> gridThe grid created byreadGrid(FloatBuffer, Loader, Path)
.
-
-
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 thefloat
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
Returnstrue
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
Returns the next word from an ASCII file. This method is invoked only for parsing ASCII files, in which case theascii
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:- On an instance created for the latitude shifts file with a
latitude
argument set to null. - On an instance created for the longitude shifts file with a
latitude
argument set to the instance created in the previous step.
grid
field.- Parameters:
fb
- aFloatBuffer
view over the fullDatumShiftGridLoader.buffer
range.latitudeShifts
- the previously loaded latitude shifts, ornull
if not yet loaded.longitudeShifts
- the file for the longitude grid.- Throws:
IOException
org.opengis.util.FactoryException
org.opengis.referencing.operation.NoninvertibleTransformException
- On an instance created for the latitude shifts file with a
-
fillBuffer
Invoked when the givenFloatBuffer
buffer is empty. This method requests onefloat
from the channel, but the channel will usually give us as many data as the buffer can contain.- Throws:
IOException
-
syncView
Sets the position and limit of the givenFloatBuffer
to the same position and limit than the underlyingByteBuffer
, converted to units offloat
data type.
-