RasterMissingValuesFiller¶
Fills the holes of a raster, its no-data cells, by interpolation of the valid cells around them. It repairs the gaps of elevation models from lidar or photogrammetry, under water surfaces or dense vegetation, and the cells lost by a processing, and it can fill rasters of classes without inventing new classes.
Details¶
Every novalue cell is filled from the valid cells within the max distance, measured in cells from center to center, so a circle of radius pMaxDistance. The cells at the min distance or nearer are not used: a min distance of 1 or 2 skips the edge cells of the holes, which in lidar or photogrammetric models are often wrong. With the only border values switch, just the valid cells touching a hole (in the 8 directions) are used, the ones on the rim of the holes: the interior of the valid area doesn’t weigh on the fill, and on large rasters it is faster.
A cell is filled only if at least 4 valid cells are found, otherwise it stays novalue: the holes wider than about twice the max distance keep a novalue core. The filled cells are not used to fill the others, so the result doesn’t depend on the order of the cells.
The modes are inverse distance weighting (IDW, weights 1/d²), linear distance weighting (LDW), thin plate spline (TPS), the plain average (AVERAGING) and, for rasters of classes, the most frequent value (CATEGORIES), that never creates values that are not in the input.
Every novalue cell is a hole, also the ones outside the area of the data, as the border of a basin or the frame of an orthophoto: without a mask the valid area grows outwards by the max distance. A raster mask (on the grid of the input) or a vector mask of polygons limits the fill to its valid cells or to its area.
Parameters¶
Fills the missing values (holes) of a raster by interpolation of the valid cells around them.
Toolbox folder: Raster Processing
Status: Certified
Keywords: Null, Missing values, Holes, Interpolation, Raster
Authors: Andrea Antonello
Class: org.hortonmachine.modules.RasterMissingValuesFiller
Inputs
Parameter |
Type |
Unit |
Default |
Description |
|---|---|---|---|---|
|
raster file |
The raster in which to fill missing values. |
||
|
raster file |
An optional raster mask, on the grid of the input: only the holes on its valid cells are filled. |
||
|
vector file |
An optional vector mask of polygons: only the holes inside them are filled. |
||
|
int |
|
The cells at this distance or nearer are not used for the interpolation (in cells). |
|
|
int |
|
The max distance of the cells used for the interpolation (in cells). |
|
|
boolean |
|
Use only the valid cells touching the holes, instead of all the valid cells within the max distance. |
|
|
String |
|
The interpolation mode. Allowed values: |
Outputs
Parameter |
Type |
Unit |
Description |
|---|---|---|---|
|
output file |
The filled raster. |
Example¶
The example runs on the sample elevation model of the manual, dtm_flanginec.tif in docs/manual/modules/maps/data, each module on the outputs of the previous ones. It first makes holes of 60 by 60 m in the elevation with Mapcalc, then fills them:
import org.hortonmachine.modules.Mapcalc
import org.hortonmachine.modules.RasterMissingValuesFiller
// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"
// holes of 60 x 60 m every 400 m in the elevation model
var mapcalc = new Mapcalc()
mapcalc.inRaster1 = folder + "dtm_flanginec.tif"
mapcalc.pFunction = """
images { dtm_flanginec = read; dtm_holes = write; }
hole = (x() - xmin()) % 400 < 60 && (y() - ymin()) % 400 < 60;
dtm_holes = hole ? null : dtm_flanginec;
"""
mapcalc.outRaster = folder + "dtm_holes.tif"
mapcalc.process()
// filled with a thin plate spline through the rim of each hole; the mask keeps the novalue
// frame of the elevation model out, else the fill would extend the model over it
var filler = new RasterMissingValuesFiller()
filler.inRaster = folder + "dtm_holes.tif"
filler.inMask = folder + "dtm_flanginec.tif"
filler.pMaxDistance = 10
filler.doUseOnlyBorderValues = true
filler.pMode = "TPS"
filler.outRaster = folder + "dtm_filled.tif"
filler.process()
The sample elevation model with a hole of 60 by 60 m every 400 m.¶
The holes filled with a thin plate spline through their rims: the mask leaves the frame of the model as it is.¶