layout: default title: addDTM parent: Grid Tools nav_order: 3 —
addDTM
Description
addDTM is a command-line utility for combining two JHC-format 32-bit floating-point grid files (.r4 files) or adding a constant value to a base grid. It takes a “base” grid and an “on-top” grid (or a constant), applies a multiplier and offset to the “on-top” data, and then adds (or subtracts) it to the base grid. The result is a new 32-bit floating-point grid file. This tool is useful for creating synthetic bathymetry, applying corrections, or combining different terrain models.
Usage
addDTM [OPTIONS] -base <base_r4_file> [-ontop <second_r4_file> | -addConstant <value>] -out <output_r4_file>
Note: You must either provide -ontop or -addConstant, but not necessarily both.
Arguments
| Option | Description | Default / Example |
|---|---|---|
-base <base_r4_file> | Required. Specifies the path to the base input JHC-format 32-bit floating-point grid file. | base_bath.r4 |
-ontop <second_r4_file> | Specifies the path to the second input JHC-format 32-bit floating-point grid file whose values will be added/subtracted from the base. | correction.r4 |
-addConstant <value> | Instead of an “on-top” file, a constant float value can be added to every non-zero point in the base grid. | 10.5 |
-out <output_r4_file> | Required. Specifies the path for the output JHC-format 32-bit floating-point grid file. | combined_bath.r4 |
-subtract | If specified, the (scaled and offset) “on-top” values (or constant) will be subtracted from the base grid instead of added. | (Adds by default) |
-offset <value> | A floating-point offset value applied to the “on-top” grid’s values before multiplication and addition/subtraction. This offset is subtracted from the “on-top” values. | 0.0 |
-multiplier <value> | A scaling factor applied to the “on-top” grid’s values (after offset) before addition/subtraction. | 1.0 |
-addtoZero | Modifies the behavior for handling zero values. If this flag is present, a ZERO value becomes 9999999.99 internally, affecting how operations are performed on grid cells that might otherwise be considered “no data” or ignored. Used in conjunction with useZeroAdd. | |
-useZeroAdd | If set, it forces operations even on “on-top” grid cells that are zero, if the base grid cell is non-zero. Otherwise, a zero in the “on-top” grid is treated as “no data” and the base value is retained. | |
-v | Enable verbose output during processing. |
How It Works
- File Opening: Opens the base input
.r4file, the optional “on-top” input.r4file, and the output.r4file. - Header Reading: Reads the
JHC_headerfrom the base file and the “on-top” file (if provided), ensuring their dimensions match. - Data Processing: Iterates through each pixel in the grids:
- Reads the float value from the base grid.
- If
-ontopis used: Reads the float value from the “on-top” grid. If this value is0.0and-useZeroAddis not set, the base value is retained. Otherwise, the “on-top” value is adjusted byoffsetandmultiplier. - If
-addConstantis used: TheaddConstantvalue is used as the “on-top” value. - If
-subtractis used, the adjusted “on-top” value is subtracted from the base value. Otherwise, it is added. - The result is written to the output
.r4file.
- Output Header: Creates a
JHC_headerfor the output file (copied from the base file’s header, with updatedmin_valueandmax_value) and writes it to the output file.
Output Files
<output_r4_file>: A new JHC-format 32-bit floating-point grid file (.r4).
Dependencies
array.h: ForJHC_headerstructure and related functions.support.h: For general utility functions and error handling.
Notes
This tool is flexible for combining or modifying elevation models by applying either another grid or a constant value. The addtoZero and useZeroAdd options provide control over how zero values (often representing “no data”) are handled during calculations.