Class Etopo5Loader

java.lang.Object
edu.cnu.mdi.mapping.loader.Etopo5Loader

public final class Etopo5Loader extends Object
Loader/query class for the NOAA ETOPO5 global relief grid.

ETOPO5.DAT is a global 5 arc-minute grid stored as signed 16-bit big-endian integers. Each value is an elevation in meters, with negative values representing ocean depth.

Grid layout

  • 2160 latitude rows
  • 4320 longitude columns
  • 5 arc-minute spacing = 1/12 degree
  • first row: 90 degrees north
  • rows proceed southward
  • columns proceed eastward from 0 degrees longitude

This class loads the whole grid into memory. That is only about 18.7 MB of raw data, plus Java array overhead, so it is quite reasonable for a MDI mapping demo.

  • Field Details

    • DEFAULT_RESOURCE

      public static final String DEFAULT_RESOURCE
      Default classpath location based on src/main/resources layout.
      See Also:
    • ROWS

      public static final int ROWS
      Number of latitude rows in ETOPO5.
      See Also:
    • COLS

      public static final int COLS
      Number of longitude columns in ETOPO5.
      See Also:
    • STEP_DEGREES

      public static final double STEP_DEGREES
      Grid spacing in degrees: 5 arc-minutes = 1/12 degree.
      See Also:
  • Method Details

    • loadDefaultResource

      public static Etopo5Loader loadDefaultResource() throws IOException
      Loads ETOPO5 from the default classpath resource:
       /edu/cnu/mdi/etopo5/ETOPO5.DAT
       
      Returns:
      loaded ETOPO5 grid
      Throws:
      IOException - if the resource cannot be found or read
    • loadFromResource

      public static Etopo5Loader loadFromResource(String resourcePath) throws IOException
      Loads ETOPO5 from a classpath resource.
      Parameters:
      resourcePath - absolute classpath resource path
      Returns:
      loaded ETOPO5 grid
      Throws:
      IOException - if the resource cannot be found or read
    • load

      public static Etopo5Loader load(Path path) throws IOException
      Loads ETOPO5 from a filesystem path.
      Parameters:
      path - path to ETOPO5.DAT
      Returns:
      loaded ETOPO5 grid
      Throws:
      IOException - if the file cannot be read or has the wrong size
    • getElevationMeters

      public int getElevationMeters(double latitudeDegrees, double longitudeDegrees)
      Returns the nearest-neighbor elevation in meters for a latitude and longitude given in degrees.

      Latitude is clamped to the legal range [-90, 90]. Longitude is wrapped into [0, 360).

      Parameters:
      latitudeDegrees - latitude in degrees, north positive
      longitudeDegrees - longitude in degrees, east positive
      Returns:
      elevation in meters; negative values are below sea level
      Throws:
      IllegalArgumentException - if either coordinate is not finite
    • getInterpolatedElevationMeters

      public double getInterpolatedElevationMeters(double latitudeDegrees, double longitudeDegrees)
      Returns bilinearly interpolated elevation in meters.

      This is smoother for mouse-over feedback or color shading. The result is a double because it is an interpolation of nearby integer grid values.

      Parameters:
      latitudeDegrees - latitude in degrees, north positive
      longitudeDegrees - longitude in degrees, east positive
      Returns:
      interpolated elevation in meters
      Throws:
      IllegalArgumentException - if either coordinate is not finite
    • getElevationMetersAtGridPoint

      public int getElevationMetersAtGridPoint(int row, int col)
      Returns the raw grid value at a row and column.
      Parameters:
      row - row index in the range 0 <= row < 2160
      col - column index in the range 0 <= col < 4320
      Returns:
      elevation in meters
    • rowToLatitudeDegrees

      public static double rowToLatitudeDegrees(int row)
      Converts a grid row to latitude in degrees.
      Parameters:
      row - grid row
      Returns:
      latitude in degrees
    • colToLongitudeDegrees

      public static double colToLongitudeDegrees(int col)
      Converts a grid column to longitude in degrees, in [0, 360).
      Parameters:
      col - grid column
      Returns:
      longitude in degrees