I have a large land cover raster with classified integer values from 2-22. There are some single or double pixel no-data gaps where I merged 2 adjacent tifs together. If this were a continuous raster I would use the GDAL fill nodata tool to remove these holes but because this is a discrete raster I need to preserve the values I would like a tool that uses the majority value of the pixels adjacent to the nodata pixel instead of the interpolated value.

  • You have GRASS installed? Try r.neighbors
    – BERA
    Aug 20, 2020 at 19:02
  • That might work using the mode setting if I create a selection map that is only the null pixels.
    – Baswein
    Aug 20, 2020 at 19:21

1 Answer 1


Past self, you can use the Grass algorithm r.neighbors in QGIS to do this.

First create a mask layer that is the inverse of the layer you want to fill. This means that all the NoData cells you want to be filled need to have a value, any value, and all the other cells are NoData.

  1. Run the Fill NoData Cells algo with a value not in the rest of your dataset.

  2. Run the Reclassify by Table with a single row that is the former NoData value you just assigned as Min, Max, and Value.
    reclass table
    Turn on the use no data when no range matches value to make all other values in the dataset NoData.
    Fill NoData Cells Screenshot

  3. Then run r.neighbors with your original layer as your Input Raster Layer and your mask layer as your Raster layer to select the cells which should be processed. Set the Neighborhood operation to mode. The neighborhood size is a bit tricky. You want it to be large enough to fill your largest gaps but not so large that it throws off your values or takes forever to run.

If you set up a model maybe keep the value low and run it a number of times.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.