Learn R Programming

gdalraster (version 1.11.1)

fillNodata: Fill selected pixels by interpolation from surrounding areas

Description

fillNodata() is a wrapper for GDALFillNodata() in the GDAL Algorithms API. This algorithm will interpolate values for all designated nodata pixels (pixels having an intrinsic nodata value, or marked by zero-valued pixels in the optional raster specified in mask_file). For each nodata pixel, a four direction conic search is done to find values to interpolate from (using inverse distance weighting). Once all values are interpolated, zero or more smoothing iterations (3x3 average filters on interpolated pixels) are applied to smooth out artifacts.

Usage

fillNodata(
  filename,
  band,
  mask_file = "",
  max_dist = 100,
  smooth_iterations = 0L,
  quiet = FALSE
)

Value

Logical indicating success (invisible TRUE). An error is raised if the operation fails.

Arguments

filename

Filename of input raster in which to fill nodata pixels.

band

Integer band number to modify in place.

mask_file

Optional filename of raster to use as a validity mask (band 1 is used, zero marks nodata pixels, non-zero marks valid pixels).

max_dist

Maximum distance (in pixels) that the algorithm will search out for values to interpolate (100 pixels by default).

smooth_iterations

The number of 3x3 average filter smoothing iterations to run after the interpolation to dampen artifacts (0 by default).

quiet

Logical scalar. If TRUE, a progress bar will not be displayed. Defaults to FALSE.

Examples

Run this code
## fill nodata edge pixels in the elevation raster
elev_file <- system.file("extdata/storml_elev.tif", package="gdalraster")

## get count of nodata
tbl <- buildRAT(elev_file)
head(tbl)
tbl[is.na(tbl$VALUE),]

## make a copy that will be modified
mod_file <- file.path(tempdir(), "storml_elev_fill.tif")
file.copy(elev_file,  mod_file)

fillNodata(mod_file, band=1)

mod_tbl = buildRAT(mod_file)
head(mod_tbl)
mod_tbl[is.na(mod_tbl$VALUE),]

deleteDataset(mod_file)

Run the code above in your browser using DataLab