org.gcube.contentmanagement.timeseries.geotools.vti.connectors
Class VTIBathymetry

java.lang.Object
  extended by org.gcube.contentmanagement.timeseries.geotools.vti.connectors.VTIBathymetry

public class VTIBathymetry
extends java.lang.Object

Class for obtaining altimetry and bathymetry values from a netCDF file. Requires the netCDF libraries (see here: http://www.unidata.ucar.edu/software/netcdf-java/documentation.htm) You should use the class in the following way:

   VTIBathymetry bath = new VTIBathymetry("/path/to/bath.nc");   // e.g. gebco_08.nc
   bath.open();                                                  // file must be explicitly opened, this takes a short time, avoid opening it several times
   short value1 = bath.getZ(142.2, 11.35);                       // e.g. Mariana Trench
   short value2 = bath.getZ(0, 0);
   // ...
   bath.close();                                                 // file should be closed when not needed any longer
 

Author:
Frank Loeschau, Terradue Srl.

Field Summary
 int GRID_COLS
           
 int GRID_ROWS
           
 
Constructor Summary
VTIBathymetry(java.lang.String filename)
          Creates an instance of VTIBathymetry with the specified file.
 
Method Summary
 void close()
          Closes the netCDF file.
 short getZ(double x, double y)
          Returns the altimetric/bathymetric value of the given geographical coordinates.
 short getZ(java.awt.geom.Point2D.Double point)
          Returns the altimetric/bathymetric value of the given geographical coordinates.
 short[] getZ(java.awt.geom.Point2D.Double[] points)
          Returns the altimetric/bathymetric values of the given array of geographical coordinates.
static void main(java.lang.String[] args)
          The class can also be used as command-line tool.
 void open()
          Opens the netCDF file and loads the data array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRID_COLS

public final int GRID_COLS
See Also:
Constant Field Values

GRID_ROWS

public final int GRID_ROWS
See Also:
Constant Field Values
Constructor Detail

VTIBathymetry

public VTIBathymetry(java.lang.String filename)
Creates an instance of VTIBathymetry with the specified file.

Parameters:
filename - the netCDF filename containing the altimetry/bathymetry data
Method Detail

main

public static void main(java.lang.String[] args)
The class can also be used as command-line tool. The syntax is:

java org.d4science2.vtivre.VTIBathymetry get x1,y1 [x2,y2 [...]] filename

If only one pair of coordinates is specified, debug information about the calculation is written.

Parameters:
args - the command-line arguments

open

public void open()
          throws java.io.IOException
Opens the netCDF file and loads the data array. This operation is somewhat slow and requires the creation of a big object in memory. Ideally, this method is called only once, before the altrimetry/bathymetry values are needed.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes the netCDF file.

Throws:
java.io.IOException

getZ

public short getZ(java.awt.geom.Point2D.Double point)
           throws java.io.IOException
Returns the altimetric/bathymetric value of the given geographical coordinates. The value derives from the corresponding cell in the coordinate grid (120 x 120 cells per degree). If a coordinate is close to the cell border (< 0.1 * arc cell size), the result value is averaged with the value from the adjacent cell.

Parameters:
point - the geographical coordinates (x = longitude value (-180 to 180), y = latitude value (-90 to 90))
Returns:
the altimetric/bathymetric value for the coordinate (in meters)
Throws:
java.io.IOException - if the netCDF variable z could not been read

getZ

public short[] getZ(java.awt.geom.Point2D.Double[] points)
             throws java.io.IOException
Returns the altimetric/bathymetric values of the given array of geographical coordinates. The value derives from the corresponding cell in the coordinate grid (120 x 120 cells per degree). If a coordinate is close to the cell border (< 0.1 * arc cell size), the result value is averaged with the value from the adjacent cell.

Parameters:
points - array of geographical coordinates (x = longitude value (-180 to 180), y = latitude value (-90 to 90))
Returns:
an array of the same shape as points, containing the altimetric/bathymetric value for the coordinate (in meters)
Throws:
java.io.IOException - if the netCDF variable z could not been read

getZ

public short getZ(double x,
                  double y)
           throws java.lang.NullPointerException,
                  java.io.IOException
Returns the altimetric/bathymetric value of the given geographical coordinates. The value derives from the corresponding cell in the coordinate grid (120 x 120 cells per degree). If a coordinate is close to the cell border (< 0.1 * arc cell size), the result value is averaged with the value from the adjacent cell.

Parameters:
x - longitude coordinate (-180 to 180)
y - latitude coordinate (-90 to 90)
Returns:
the altimetric/bathymetric value for the coordinate (in meters)
Throws:
java.lang.NullPointerException - if the netCDF file has not been opened or the variable z (containing the altimetry/bathymetry values) is not found
java.io.IOException - if the netCDF variable z could not been read