Class NTV2GridShiftFile
- java.lang.Object
-
- org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFile
-
- All Implemented Interfaces:
java.io.Serializable
public class NTV2GridShiftFile extends java.lang.Object implements java.io.Serializable
Models the NTv2 format Grid Shift File and exposes methods to shift coordinate values using the Sub Grids contained in the file.The principal reference for the algorithms used is the 'GDAit Software Architecture Manual' produced by the Geomatics Department of the University of Melbourne
This library reads binary NTv2 Grid Shift files in Big Endian (Canadian standard) or Little Endian (Australian Standard) format. The older 'Australian' binary format is not supported, only the official Canadian format, which is now also used for the national Australian Grid.
Grid Shift files can be read as InputStreams or RandomAccessFiles. Loading an InputStream places all the required node information (accuracy data is optional) into heap based Java arrays. This is the highest performance option, and is useful for large volume transformations. Non-file data sources (eg using an SQL Blob) are also supported through InputStream. The RandomAccessFile option has a much smaller memory footprint as only the Sub Grid headers are stored in memory, but transformation is slower because the file must be read a number of times for each transformation.
Coordinates may be shifted Forward (ie from and to the Datums specified in the Grid Shift File header) or Reverse. The reverse transformation uses an iterative approach to approximate the Grid Shift, as the precise transformation is based on 'from' datum coordinates.
Coordinates may be specified either in Seconds using Positive West Longitude (the original NTv2 arrangement) or in decimal Degrees using Positive East Longitude.
- Since:
- 2507
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringfromEllipsoidprivate doublefromSemiMajorAxisprivate doublefromSemiMinorAxisprivate NTV2SubGridlastSubGridprivate intoverviewHeaderCountprivate static longserialVersionUIDprivate java.lang.StringshiftTypeprivate intsubGridCountprivate intsubGridHeaderCountprivate java.lang.StringtoEllipsoidprivate NTV2SubGrid[]topLevelSubGridprivate doubletoSemiMajorAxisprivate doubletoSemiMinorAxisprivate java.lang.Stringversion
-
Constructor Summary
Constructors Constructor Description NTV2GridShiftFile()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static NTV2SubGrid[]createSubGridTree(NTV2SubGrid... subGrid)Create a tree of Sub Grids by adding each Sub Grid to its parent (where it has one), and returning an array of the top level Sub Gridsjava.lang.StringgetFromEllipsoid()Returns "from" ellipsoid identifier.private static NTV2SubGridgetSubGrid(NTV2SubGrid[] topLevelSubGrid, double lon, double lat)Find the finest SubGrid containing the coordinate, specified in Positive West Secondsjava.lang.StringgetToEllipsoid()Returns "to" ellipsoid identifier.booleangridShiftForward(NTV2GridShift gs)Shift a coordinate in the Forward direction of the Grid Shift File.booleangridShiftReverse(NTV2GridShift gs)Shift a coordinate in the Reverse direction of the Grid Shift File.voidloadGridShiftFile(java.io.InputStream in, boolean loadAccuracy)Load a Grid Shift File from an InputStream.private static voidreadBytes(java.io.InputStream in, byte[] b)java.lang.StringtoString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
overviewHeaderCount
private int overviewHeaderCount
-
subGridHeaderCount
private int subGridHeaderCount
-
subGridCount
private int subGridCount
-
shiftType
private java.lang.String shiftType
-
version
private java.lang.String version
-
fromEllipsoid
private java.lang.String fromEllipsoid
-
toEllipsoid
private java.lang.String toEllipsoid
-
fromSemiMajorAxis
private double fromSemiMajorAxis
-
fromSemiMinorAxis
private double fromSemiMinorAxis
-
toSemiMajorAxis
private double toSemiMajorAxis
-
toSemiMinorAxis
private double toSemiMinorAxis
-
topLevelSubGrid
private NTV2SubGrid[] topLevelSubGrid
-
lastSubGrid
private NTV2SubGrid lastSubGrid
-
-
Constructor Detail
-
NTV2GridShiftFile
public NTV2GridShiftFile()
-
-
Method Detail
-
readBytes
private static void readBytes(java.io.InputStream in, byte[] b) throws java.io.IOException
- Throws:
java.io.IOException
-
loadGridShiftFile
public void loadGridShiftFile(java.io.InputStream in, boolean loadAccuracy) throws java.io.IOException
Load a Grid Shift File from an InputStream. The Grid Shift node data is stored in Java arrays, which will occupy about the same memory as the original file with accuracy data included, and about half that with accuracy data excluded. The size of the Australian national file is 4.5MB, and the Canadian national file is 13.5MBThe InputStream is closed by this method.
- Parameters:
in- Grid Shift File InputStreamloadAccuracy- is Accuracy data to be loaded as well as shift data?- Throws:
java.io.IOException- if any I/O error occurs
-
createSubGridTree
private static NTV2SubGrid[] createSubGridTree(NTV2SubGrid... subGrid)
Create a tree of Sub Grids by adding each Sub Grid to its parent (where it has one), and returning an array of the top level Sub Grids- Parameters:
subGrid- an array of all Sub Grids- Returns:
- an array of top level Sub Grids with lower level Sub Grids set.
-
gridShiftForward
public boolean gridShiftForward(NTV2GridShift gs)
Shift a coordinate in the Forward direction of the Grid Shift File.- Parameters:
gs- A GridShift object containing the coordinate to shift- Returns:
- True if the coordinate is within a Sub Grid, false if not
-
gridShiftReverse
public boolean gridShiftReverse(NTV2GridShift gs)
Shift a coordinate in the Reverse direction of the Grid Shift File.- Parameters:
gs- A GridShift object containing the coordinate to shift- Returns:
- True if the coordinate is within a Sub Grid, false if not
-
getSubGrid
private static NTV2SubGrid getSubGrid(NTV2SubGrid[] topLevelSubGrid, double lon, double lat)
Find the finest SubGrid containing the coordinate, specified in Positive West Seconds- Parameters:
topLevelSubGrid- top level subgridlon- Longitude in Positive West Secondslat- Latitude in Seconds- Returns:
- The SubGrid found or null
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getFromEllipsoid
public java.lang.String getFromEllipsoid()
Returns "from" ellipsoid identifier.- Returns:
- "from" ellipsoid identifier
-
getToEllipsoid
public java.lang.String getToEllipsoid()
Returns "to" ellipsoid identifier.- Returns:
- "to" ellipsoid identifier
-
-