RasterDiff

Subtracts a raster from another, cell by cell. The typical use is the canopy height model, the height of the vegetation over the ground, from the surface model of a lidar survey minus its terrain model. The surface often dips a bit under the terrain because of the noise of the two models, so the negative differences can be set to 0, and the low vegetation and the ground can be left out with a threshold.

It is a shortcut for the most common expression of Mapcalc, which it runs inside: Mapcalc is the tool for any other combination of rasters.

Details

The result is the first raster minus the second one, on the grid of the first: the two rasters need the same grid. A cell that is novalue in one of them is novalue in the result. Without the negatives the differences below 0 become 0, as the canopy that can’t be below the ground in a surface model minus a terrain model with some noise. The threshold then sets to novalue the differences below it, as the low vegetation and the ground under a canopy height model of 2 m.

It is a shortcut for the most common Mapcalc expression: Mapcalc is the tool for any other combination of rasters.

Parameters

Subtracts a raster from another, cell by cell, as the canopy height model from the surface and the terrain models.

Toolbox folder: Raster Processing
Status: Certified
Keywords: Raster, Difference, Subtract, Canopy height model
Authors: Andrea Antonello
Class: org.hortonmachine.modules.RasterDiff

Inputs

Parameter

Type

Unit

Default

Description

inRaster1

raster file

The raster to subtract from.

inRaster2

raster file

The raster to subtract, on the grid of the first one.

pThreshold

Double

An optional threshold: the differences below it become novalue.

doNegatives

boolean

true

If false, the negative differences become 0.

Outputs

Parameter

Type

Unit

Description

outRaster

output file

The difference of the rasters.

Example

The example runs on the sample data of the manual, in docs/manual/modules/maps/data, each module on the outputs of the previous ones. It takes the surface of the lidar plot interpolated by SurfaceInterpolator minus the terrain model of the plot:

import org.hortonmachine.modules.RasterDiff

// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"

// the canopy height model of the lidar plot: the surface of SurfaceInterpolator minus the terrain
var diff = new RasterDiff()
diff.inRaster1 = folder + "dsm_777.tif"
diff.inRaster2 = folder + "dtm_777.tif"
// the canopy can't be below the ground
diff.doNegatives = false
// the vegetation under 2 m is left out
diff.pThreshold = 2.0
diff.outRaster = folder + "chm_777.tif"
diff.process()
The canopy height model of the lidar plot: the crowns of the trees above 2 m, the rest novalue.

The canopy height model of the lidar plot: the crowns of the trees above 2 m, the ground and the low vegetation left out.