gdal_fillnodata
What is gdal_fillnodata?
gdal_fillnodata.py replaces NoData pixels in a raster with interpolated values computed from neighbouring valid pixels. It uses an inverse-distance weighted average of pixels found around the edge of each gap, followed by optional smoothing passes. This is the standard tool for closing voids in DEMs (classic SRTM gaps), patching missing scanlines in satellite imagery, or cleaning up mask-induced holes after a processing step.
gdal_fillnodata.py [options] <src_filename> [<dst_filename>]Commonly used options:
-md <max_distance>— maximum search distance in pixels (default 100)-si <smoothing_iterations>— number of 3×3 smoothing iterations after fill (default 0)-b <band>— source band (default 1)-mask <filename>— external mask (pixels =0 are considered NoData)-nomask— ignore the band mask-of <format>— output driver-co <NAME>=<VALUE>— creation options
If <dst_filename> is omitted, the input raster is modified in place.
When would you use gdal_fillnodata?
Use it whenever small NoData regions interrupt an otherwise continuous raster. Typical jobs: filling voids in an SRTM DEM before hydrological modelling (gdal_fillnodata.py -md 50 -si 2 srtm.tif srtm_filled.tif), patching cloud-masked pixels in an NDVI composite with a short search radius to avoid blurring, or closing mask-edge artefacts after a cutline-based clip. Pair with gdal_sieve upstream if the NoData regions include isolated noise pixels you want to merge into their neighbours.
The -md value matters. Small radii (5–20 pixels) preserve local structure on noisy terrain; large radii (100+) can fill bigger voids but blur the result and may cross meaningful boundaries. Add -si 1 or -si 2 to soften the interpolation seam between original and filled regions — higher smoothing counts can start over-smoothing valid pixels nearby.
FAQs
When should I prefer a different gap-fill method?
gdal_fillnodata.py is an IDW-from-the-edge algorithm — it does a decent job on small, roughly circular gaps but struggles on long narrow voids (e.g. dropped scanlines crossing mountains) and on gaps larger than -md. For DEM-specific void-filling, consider SAGA GIS's Grid Gaps Close or gdaldem with external reference DEMs, or fill with a downsampled reference raster using gdalwarp -srcnodata -dstnodata. For imagery, median-composite methods over a time series often beat spatial interpolation.
What is -md and how do I pick a value?
-md is the maximum search radius in pixels for finding valid neighbours. Set it to at least half the width of the largest void you want to close, but not so large that it bridges features you want to preserve. For a 30-metre DEM with voids up to 500 m across, -md 10 is insufficient; -md 20 is about right.
Does this modify my source file?
Yes, if you omit the destination argument — gdal_fillnodata.py src.tif writes filled pixels back into src.tif in place. Always provide an explicit destination when you want a new file: gdal_fillnodata.py src.tif dst.tif. The in-place behaviour is handy for iterative pipelines but dangerous for source data.
Why do I see visible seams at the edge of filled regions?
Pure IDW fills produce a subtle discontinuity where interpolated pixels meet valid ones. Add -si 1 or -si 2 to run smoothing iterations that blend the seam. More smoothing than that starts degrading legitimate pixels; at that point consider a different interpolation approach entirely.