Class GridUtilities

java.lang.Object
hec.heclib.grid.GridUtilities

public class GridUtilities extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    compares the coordinate system, cell size, and row and column positioning of two grids to determine if they are compatible for grid-to-grid operations.
    static GridData
    gridAdd(GridData grid1, GridData grid2, int[] status)
    Calculates the results of a cell-by-cell (map algebra) add on two compatible grids.
    static GridData
    gridDivide(GridData grid1, GridData grid2, int[] status)
    Calculates the results of a cell-by-cell (map algebra) divide on two compatible grids.
    static GridData
    gridMultiply(GridData grid1, GridData grid2, int[] status)
    Calculates the results of a cell-by-cell (map algebra) multiply on two compatible grids.
    static GridData
    gridSubtract(GridData grid1, GridData grid2, int[] status)
    Calculates the results of a cell-by-cell (map algebra) subtract on two compatible grids.
    static int[]
    Calculates the extent of the intersection of two compatible grids.
    static boolean
    isGridType(int type)
     
    static GridData
    mosaic(GridData inGrid1, GridData inGrid2, int[] status)
    Creates a new GridData object of the same type (HRAP, Albers, etc) as its input with new extents as specified by the row and column numbers named in its parameters.
    static GridData
    retrieveGridFromDss(String dssFileName, String path, int[] status)
    High-level call to retrieve a GridData object from a given DSS file and path.
    static GridData
    scalarAdd(GridData inGrid, float addend)
    adds the value of addend to each non-null cell in the input grid and creates a new GridData object to hold the result.
    static GridData
    scalarDivide(GridData inGrid, float divisor)
    divides the value of each non-null cell in the input grid by divisor and creates a new GridData object to hold the result.
    static GridData
    scalarMultiply(GridData inGrid, float factor)
    multiplies the value of each non-null cell in the input grid by factor and creates a new GridData object to hold the result.
    static GridData
    scalarSubtract(GridData inGrid, float subtrahend)
    subtracts the value of subtrahend from each non-null cell in the input grid and creates a new GridData object to hold the result.
    static int
    setTimeByEnd(GridData theGrid, HecTime endTime)
    changes the start and end times of a GridData object, by specifying the new end time.
    static int
    setTimeByStart(GridData theGrid, HecTime startTime)
    changes the start and end times of a GridData object by specifying the new start time.
    static int
    storeGridToDss(String dssFileName, String path, GridData theGrid)
    High-level call to store a GridData object in a given DSS file and path.
    static GridData
    subGridExtract(GridData inGrid, int xOrigin, int yOrigin, int xExtent, int yExtent, int[] status)
    Creates a new GridData object of the same type (HRAP, Albers, etc) as its input with new extents as specified by the row and column numbers named in its parameters.
    static int[]
    unionExtent(GridData grid1, GridData grid2)
    Calculates the extent of the union of two compatible grids.

    Methods inherited from class java.lang.Object

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

    • GridUtilities

      public GridUtilities()
  • Method Details

    • isGridType

      public static boolean isGridType(int type)
      Parameters:
      type - -- an integer representing and HEC-DSS data type
      Returns:
      -- True if the data type is a grid type, otherwise False
    • compatibleGrids

      public static boolean compatibleGrids(GridData grid1, GridData grid2)
      compares the coordinate system, cell size, and row and column positioning of two grids to determine if they are compatible for grid-to-grid operations.
      Parameters:
      grid1 -
      grid2 -
      Returns:
      boolean
    • storeGridToDss

      public static int storeGridToDss(String dssFileName, String path, GridData theGrid)
      High-level call to store a GridData object in a given DSS file and path.

      The D and E parts of the path will be re-set to match the start and end time of the grid as given in the GridInfo object that's part of the GridData.

      Parameters:
      dssFileName - -- New or existing DSS file
      path - -- DSS path in one string
      theGrid - -- a GridData object ready to store
      Returns:
      0 - grid successfully stored to DSS file
    • retrieveGridFromDss

      public static GridData retrieveGridFromDss(String dssFileName, String path, int[] status)
      High-level call to retrieve a GridData object from a given DSS file and path.

      On return, the value of status[0] is 0 if the retrieval is successful, -1 if the file or path can't be accessed, or -2 if the path exists but is not a grid.

      Parameters:
      dssFileName - -- New or existing DSS file
      path - -- DSS path in one string
      status - -- an integer array that will hold a status value
      Returns:
      -- a new gridData object
    • setTimeByStart

      public static int setTimeByStart(GridData theGrid, HecTime startTime)
      changes the start and end times of a GridData object by specifying the new start time. For instantaneous grids, both start and end times are set to the new time. For period grids, the method maintains the interval between start and end times to the nearest minute.

      Note that for instantaneous grids, SetTimeFromStart and SetTimeFromEnd do exactly the same thing.

      Parameters:
      theGrid - theGrid -- This is the object being changed
      startTime - theTime -- This is the new end time for the grid
      Returns:
      0 for success
    • setTimeByEnd

      public static int setTimeByEnd(GridData theGrid, HecTime endTime)
      changes the start and end times of a GridData object, by specifying the new end time. For instantaneous grids, both start and end times are set to the new time. For period grids, the method maintains the interval between start and end times to the nearest minute.

      Note that for instantaneous grids, SetTimeFromStart and SetTimeFromEnd do exactly the same thing.

      Parameters:
      theGrid - theGrid -- This is the object being changed
      endTime - theTime -- This is the new end time for the grid
      Returns:
      0 for success
    • scalarAdd

      public static GridData scalarAdd(GridData inGrid, float addend)
      adds the value of addend to each non-null cell in the input grid and creates a new GridData object to hold the result.
      Parameters:
      inGrid -
      addend -
      Returns:
    • scalarSubtract

      public static GridData scalarSubtract(GridData inGrid, float subtrahend)
      subtracts the value of subtrahend from each non-null cell in the input grid and creates a new GridData object to hold the result.
      Parameters:
      inGrid -
      subtrahend -
      Returns:
    • scalarMultiply

      public static GridData scalarMultiply(GridData inGrid, float factor)
      multiplies the value of each non-null cell in the input grid by factor and creates a new GridData object to hold the result.
      Parameters:
      inGrid -
      factor -
      Returns:
    • scalarDivide

      public static GridData scalarDivide(GridData inGrid, float divisor)
      divides the value of each non-null cell in the input grid by divisor and creates a new GridData object to hold the result.
      Parameters:
      inGrid -
      divisor -
      Returns:
    • subGridExtract

      public static GridData subGridExtract(GridData inGrid, int xOrigin, int yOrigin, int xExtent, int yExtent, int[] status)
      Creates a new GridData object of the same type (HRAP, Albers, etc) as its input with new extents as specified by the row and column numbers named in its parameters.

      This method does not do any coordinate transformations.

      The method checks the subgrid extents against the input grid extents and throws an IndexOutOfBounds exception if the range of sub-grid cell indices lies all or partly outside the bounds of the input grid.

      Parameters:
      inGrid -
      xOrigin - -- column index of subgrid origin
      yOrigin - -- row index of subgrid origin
      xExtent - -- number of columns in subgrid
      yExtent - -- number of rows in subgrid
      status - -- an integer array that will hold a status value
      Returns:
    • mosaic

      public static GridData mosaic(GridData inGrid1, GridData inGrid2, int[] status)
      Creates a new GridData object of the same type (HRAP, Albers, etc) as its input with new extents as specified by the row and column numbers named in its parameters.

      This method does not do any coordinate transformations.

      The GridInfo for the product grid is initially copied from the first input grid, so the times, units, data type, etc. are set by grid1.

      Parameters:
      inGrid1 -
      inGrid2 -
      status - -- an integer array that will hold a status value
      Returns:
    • intersectExtent

      public static int[] intersectExtent(GridData grid1, GridData grid2)
      Calculates the extent of the intersection of two compatible grids. The result is returned as an array of four integers. If the grids are not compatible, all four values are set to zero
      Parameters:
      grid1 - GridData object
      grid2 - GridData object
      Returns:
      int array representing origin indices and width and height in rows and columns [x-Origin, y-Origin, number of columns, number of rows]
    • unionExtent

      public static int[] unionExtent(GridData grid1, GridData grid2)
      Calculates the extent of the union of two compatible grids. The extent is returned as an array of four integers. If the grids are not compatible, all four values are set to zero
      Parameters:
      grid1 - GridData object
      grid2 - GridData object
      Returns:
      int array representing origin indices and width and height in rows and columns [x-Origin, y-Origin, number of columns, number of rows]
    • gridMultiply

      public static GridData gridMultiply(GridData grid1, GridData grid2, int[] status)
      Calculates the results of a cell-by-cell (map algebra) multiply on two compatible grids. If the grids are not compatible or do not intersect, a null object is returned.

      The GridInfo for the product grid is initially copied from the first input grid, so the times, units, data type, etc. are set by grid1.

      Parameters:
      grid1 - GridData object
      grid2 - GridData object
      status - int[] 0 for success; non-zero for error
      Returns:
      GridData object
    • gridDivide

      public static GridData gridDivide(GridData grid1, GridData grid2, int[] status)
      Calculates the results of a cell-by-cell (map algebra) divide on two compatible grids. If the grids are not compatible or do not intersect, a null object is returned.

      The GridInfo for the product grid is initially copied from the first input grid, so the times, units, data type, etc. are set by grid1.

      Parameters:
      grid1 - GridData object
      grid2 - GridData object
      status - int[] 0 for success; non-zero for error
      Returns:
      GridData object
    • gridAdd

      public static GridData gridAdd(GridData grid1, GridData grid2, int[] status)
      Calculates the results of a cell-by-cell (map algebra) add on two compatible grids. If the grids are not compatible or do not intersect, a null object is returned.

      The GridInfo for the product grid is initially copied from the first input grid, so the times, units, data type, etc. are set by grid1.

      Parameters:
      grid1 - GridData object
      grid2 - GridData object
      status - int[] 0 for success; non-zero for error
      Returns:
      GridData object
    • gridSubtract

      public static GridData gridSubtract(GridData grid1, GridData grid2, int[] status)
      Calculates the results of a cell-by-cell (map algebra) subtract on two compatible grids. If the grids are not compatible or do not intersect, a null object is returned.

      The GridInfo for the product grid is initially copied from the first input grid, so the times, units, data type, etc. are set by grid1.

      Parameters:
      grid1 - GridData object
      grid2 - GridData object
      status - int[] 0 for success; non-zero for error
      Returns:
      GridData object