The GridContainer Class
In HEC Java programs, GridData objects can be retrieved from and stored to HEC-DSS files using the get and put methods of the HecDss class with GridContainer objects, which are similar to other data container objects like TimeSeriesContainer or PairedDataContainer.
Table 1.1 – GridContainer Data Fields (extending DataContainer)
Field |
Type |
Description |
---|---|---|
gridData |
GridData |
A java object representing a grid (the GridData object contains a GridInfo object that holds its metadata) |
Table 1.2 – GridContainer Methods (extending DataContainer)
Method |
Returns |
Description |
---|---|---|
getGridData() |
GridData |
Retrieves the GridData object from the data container |
getGridInfo() |
GridInfo |
Retrieves the GridInfo() object from the data container (Calls getInfo() method on the GridData object held by the GridContainer) |
The data and methods listed in the tables above are in addition to those in the DataContainer base class, which are described in the Scripting chapter of the HEC-DssVue User's Manual.
Retrieving a Grid from a DSS File
Like other DSS data types, a grid can be read from a DSS file using the get() method on an HecDss object. If the get method retrieves a grid, the DataContainer object that it returns will be a GridContainer (not a TimeSeriesContainer or PairedDataContainer, which are also subclasses of DataContainer).
Example 1: Identifying Grids in a DSS File |
The Jython example above uses the HecDss.get() method to retrieve DataContainer objects from a DSS file, then tests each one, using the Python built-in function instanceof to determine whether the DataContainer objects returned are grids or other data types.
Example 2: Retrieving a GridData Object from a DSS Record |
The Jython example above retrieves a GridContainer object from a DSS record, then uses the container's getGridData() method to access the gridData object it holds. The metadata for the grid is accessed by using the getGridInfo() method on the GridData object. The same GridInfo object can be retrieved directly from the GridContainer object.
Storing a Grid to a DSS File
Grids can be stored to DSS using the put(GridContainer) method of an HecDss object.
Example 3: Storing a GridData Object to a DSS Record
|
In the Jython snippet above a new GridContainer object is created using the base GridContainer() constructor method. A DSS path (contained in the variable thePathname) and a GridData object are assigned directly to the fullName and gridData fields of the object. With those assignments, the GridData object is complete enough to be stored to a DSS record, using the put(DataContainer) method.
When using HecDss.put(GridContainer) it is very important to assure that the date or dates in the pathname are the same as those in the GridInfo. The put method does not check or update the pathname to assure consistency.