The GridData and GridInfo Classes
An object of class hec.heclib.grid.GridData is made up of a float array that holds the values of the cells in the grid, and an object of class hec.heclib.grid.GridInfo that holds metadata for the grid, including its location and extent, specified by row and column numbers.
Table 1.3 – GridData Data Fields
Field | Type | Description |
---|---|---|
_data | float[] | Holds the values for the cells in the grid. |
_gridInfo | GridInfo | Holds metadata for the grid, including data units and type, grid origin and dimensions, spatial reference system, and basic statistics. |
Notes:
- The contents of these data fields are accessible through method calls
- The 1D array maps to the 2D grid starting at the minimum X, minimum Y cell (southwest or lower left corner) and proceeding across the row, then up and across the next row, and so on. See Appendix A, esp. Figure A-1.
Table 1.4 – GridData Constructors
Method | Returns | Description |
---|---|---|
GridData() | GridData | Constructor method; produces an empty GridData object. |
GridData( float[] data, GridInfo info) | GridData | Assigns float array and the GridInfo object given in the arguments to a new GridData object. |
GridData(GridData gridData) | GridData | Copy constructor. |
Notes:
The GridData(float[] array, GridInfo info) constructor assigns the objects named in the arguments directly to the new GridData object. The contents of the data fields are not copied, so they can be changed either through the methods of the GridData object or by continued reference to the variables used as arguments in the constructor.
- The GridData(GridData gridData) constructor creates copies of the contents of the GridData object named as its argument. The new object is completely independent of the object it was copied from.
Table 1.5 – GridData Data Access
Method | Returns | Description |
---|---|---|
getData() | float[] | Access to the values as an array of floats. |
setData(float[] array) | None | Assigns a new value array to the grid. |
getGridInfo() | GridInfo | Retrieves the GridInfo() object. |
initGridInfo | None | Assigns a new GridInfo object to the grid. |
getValueAt(int X, int Y) | double | Returns value in cell at column X, row Y. |
initGridData( float[] data, GridInfo, info) | None | Sets data and metadata for an existing GridData object. The contents of arguments are copied to the GridData object. |
setValueAt(int X, int Y, float value) | None | Sets value in cell at column X, row Y |
setValueAt(int X, int Y, double value) | None | Sets value in cell at column X, row Y |
Notes:
- The setData and initGridInfo methods assign their arguments directly to the GridData object. The objects named by the argument are not
The initGridData(float[] array, GridInfo gridInfo) method creates copies of the contents its arguments. The argument objects remain independent of the updated GridData object.
Table 1.6 – GridData Utility Methods
Method | Returns | Description |
---|---|---|
updateStatistics() | None | Re-calculates min, max, mean statistics for the values in the grid cells. |
getNumberMissing() | Int | Number of cell with null or missing values. |
roundValues(int precision) | Int | Performs decimal rounding to number of digits named by argument. Returns 0 for success. |
initGridData( float[] data, GridInfo, info) | None | Copies data and metadata from arguments to an existing GridData object. |
setValueAt(int X, int Y, float value) | None | Sets value in cell at column X, row Y |
setValueAt(int X, int Y, double value) | None | Sets value in cell at column X, row Y |
Notes:
- The roundValues method can be used to reduce the number of unique values in the data array, making data compression more effective. The precision argument sets the number of digits past the decimal point: precision 0 rounds to whole numbers, precision 1 rounds to tenths, etc. Since Java floats are IEEE values with a base of 2, decimal rounding is approximate. Use with caution.
The initGridData(float[] array, GridInfo gridInfo) method creates copies of the contents its arguments. The argument objects remain independent of the updated GridData object.
Utility Functions for Grids
The Java class hec.heclib.grid.GridUtilities contains static methods for operations on GridData and GridInfo objects. These methods can be made available for use in Jython scripts in DSSVue by importing hec.heclib.grid and referencing the methods as GridUtility.method(arguments).
The descriptions of the methods in GridUtilities in this chapter refer to the lower-level classes GridData, GridInfo, and GriddedData. These classes are described in more detail in Chapter 1.