Skip to content

Documentation / @interstellar-tools/maps / terrainRoughnessIndexAt

Function: terrainRoughnessIndexAt() ​

ts
function terrainRoughnessIndexAt(
  grid: GridInterface,
  row: number,
  column: number
): number;

Defined in: terrain/terrain-roughness-index.ts:53

Compute the Terrain Roughness Index of an elevation grid at a cell: the root-mean-square height difference between the cell and its eight neighbours.

TRI=18∑i=18(zi−z0)2

Where:

  • z0 is the cell's height (m)
  • zi are the heights of its eight neighbours (m)

Units

  • Input: heights in m.
  • Output: TRI in m, ≥ 0: 0 is level.

Notes

  • How uneven the ground is around a cell: boulders, crags and small craters, the things that tip a lander, rather than how steep it is. A cell 1 m above level surroundings has a TRI of 1 m. A smooth slope has a TRI too, about its rise over one cell, so read it together with slopeAt.
  • Other definitions are in use. Riley et al. (1999), who named the Terrain Ruggedness Index, leave out the 18, which makes theirs 8≈2.83 times this one; it's the default in gdaldem since GDAL 3.3. Wilson et al. (2007) take the mean absolute difference instead. Check which one before comparing values.
  • It compares heights only, so it depends on the cell size: a 1 m grid sees boulders, a 100 m grid only hills.
  • NaN on the grid's edge and next to a missing cell.

Parameters ​

ParameterTypeDescription
gridGridInterfaceElevation grid, heights in m.
rownumberRow index, 0 at the north edge (an integer in [0, rows)).
columnnumberColumn index, 0 at the west edge (an integer in [0, columns)).

Returns ​

number

The TRI in m, or NaN where it can't be computed.

Throws ​

If row or column is not an integer inside the grid.

Example ​

ts
// A 2 m boulder on level ground
const grid = createGrid({
  rows: 3,
  columns: 3,
  values: [0, 0, 0, 0, 2, 0, 0, 0, 0],
  cellSize: { x: 1, y: 1 }
});

terrainRoughnessIndexAt(grid, 1, 1); // 2

See ​