The Grid Calculator command allows the users to perform algebraic computations on raster grids based on existing raster pixel values. The user can perform mathematical operations on each cell in a raster. This can be useful for converting and manipulating raster grids. For example, the user may want to see the difference in water surface elevations in the form of an elevation difference grid by subtracting two elevation grids from each other. Or a user may want to generate a “custom” flood hazard map by multiplying the depth raster grid with another factor.
Note that the raster grids must be loaded into the software before performing any operations on them.
Follow the steps below to use the Grid Calculator command:
- From the Terrain ribbon menu, select the Grid Calculator command.
- The Grid Calculator dialog box will be displayed.
The below sections describe how to perform algebraic computations on raster grids and interact with the above dialog box.
Selecting Raster Grids
The Grid Layers dropdown combo box lists all the loaded raster grids that can be used. To add a raster grid to the Grid Calculator Expression box, click the [Add Layer] button.
Available Grid Operators
This section contains all the available operators.
The following operators are available:
- Mathematical (+, –, *, /, sqrt)
- Trigonometric (sin, cos, tan, asin, acos, atan)
- Comparison (<, >, =, <=, >=, ≠)
- Logarithmic (log, log 10)
- Logical (And, Or)
Click the appropriate button to add an operator to the Grid Calculator Expression box.
Defining Grid Calculator Expression
The Grid Calculator Expression section is used to define the grid calculator expression.
The user can add a raster grid to the Grid Calculator Expression box and then use the operators from the Available Grid Operators section to either construct calculation expressions or type them into the box.
Defining Raster Grid Limits
The Calculated Grid Limits section allows the user to define the extent of the output raster grid. The user can choose to operate only on a portion of a source raster grid or use the entire extent of the source raster grid.
The following options are available to define the extents of the output raster grid:
- Grid source extents: On selecting this option, the output raster grid will have the same extents as the source raster grid.
- User-defined limits: This option allows the user to draw rectangular regions on the Map View in order to define the extent of the output raster grid and make the output grid smaller and easier to work with. Click the [Pick] button to define the extent of the output raster grid. On clicking the [Pick] button, the Grid Calculator dialog box will temporarily disappear, and a prompt will be displayed on the status bar instructing the user what to do next. The user can then click and drag the mouse to define the rectangular region limits of the output raster grid. Upon releasing the mouse button, the user will be returned to the dialog box and a rectangular box will be created on the source raster grid representing the user-defined region.
- Clipping polygons: This option allows the user to select one or more polygons to define the extent of the output raster grid. Click the [Pick] button to select the polygon region from the Map View. The Grid Calculator dialog box will temporarily disappear, and a prompt will be displayed on the status bar instructing the user what to do next. Select the clipping polygons on the Map View. Once finished, press the [Enter] key or right-click and select Done from the displayed context menu. The user will be returned to the dialog box. The area underneath the selected polygons will be factored in by the software as it processes the raster grid. Additionally, the user can check the Crop terrain to polygon boundary checkbox to clip the source raster grid to the boundary of the selected polygons.
Defining Raster Grid Specifications
The Calculated Grid Specifications section is used to define the specifications for the output raster grid.
Click the […] button next to the Grid file entry to specify the file name and directory location to save the output raster grid file.
By default, the Load grid as map layer checkbox option is checked to load the output raster grid as a layer in the Map Data Layers panel. Click the pencil icon to rename the layer.
The user can select the CRS to be used for the output raster grid from the Grid CRS dropdown combo box. If there is only one CRS in the project, the software automatically selects it.
The user can check the Overwrite existing grid layer checkbox option to automatically overwrite an existing raster layer (if one exists) with the revised raster layer. By default, this option is unchecked.
Performing Calculations on Raster Grids
After the options have been defined, click the [Generate] button. The software will perform calculations on the selected raster grids based on the expression defined in the Grid Calculator Expression box. An output raster grid file will be created at the specified location after the computations are finished. If the Load grid as map layer checkbox was left checked, the newly created raster grid would be added in the Map Data Layers panel.
The below sections describe various scenarios in which the grid calculator can be useful.
Convert Elevation Values from Meters to Feet
To change a raster in meters to a raster in feet, the user can use the conversion factor (3.28084) for meters to feet and create the following expression in the Grid Calculator Expression box:
“USGS DEM Meters” * 3.28084
By clicking the [Generate] button, the software will create a new raster with elevations in feet.
Using a mask
Sometimes the user might want to mask out parts of a raster. For example, consider a raster grid with elevations varying from sea level to mountain peaks. If the user is only interested in the elevation above sea level, the grid calculator can be used to create a mask, which can then be applied to the raster in a single step.
The expression will be as follows:
(“USGS DEM Meters” >= 0) * “USGS DEM Meters”
The first part of the expression in parentheses sets the value of every cell greater than or equal to zero to 1 with all other cell values set to 0. This creates the mask on the fly. The raster (USGS DEM Meters) is then multiplied by the mask values. This sets every cell with an elevation less than zero to zero.
On clicking the [Generate] button, the software will create a new raster with the mask applied.
Creating Depth Raster Grid
Depth raster grids are used to depict the depth of the river’s inundation. Grid calculator can be used to create depth raster grids by subtracting the source elevation raster grid from the water surface elevation (WSEL) raster grid. Refer to this article in our knowledge base to learn how to create a water surface elevation raster grid in HEC-RAS.
Once the source elevation and water surface elevation raster grids are available, the user can create the following expression in the Grid Calculator Expression box:
(“WSEL 100yr” – “Elev DEM Feet”)
On clicking the [Generate] button, the software will create a depth raster grid. Depth raster grids can be created for a variety of flood events illustrating the changing flood depths throughout the selected flood extent for each event.