Replace specific raster class by surrounding classes

You can convert your clouds and shadows to null / no data (e.g. by using r.null) and then interpolate those "null areas" based on the surrounding values using the Fill nodata tool, see the documentation here: https://docs.qgis.org/2.8/en/docs/user_manual/processing_algs/gdalogr/gdal_analysis/fillnodata.html

Additionally, there is a Fill gaps tool.

https://grass.osgeo.org/grass76/manuals/addons/r.fill.gaps.html

However, using Close gaps with stepwise resampling from SAGA processing toolbox might be a good alternative to Fill gaps in your usecase. Just set its Resampling method to Nearest Neighbour. This will prevent you from receiving interpolated float values from surrounding pixels and just takes the nearest (interpolated) integer neighbour value instead.

http://www.saga-gis.org/saga_tool_doc/2.2.7/grid_tools_29.html

Keep in mind the Rastertype after interpolation. Default output seems to be float32 by default. You might want to change this back to integer.


You can also do it in one step without replacing values with NULL values. Use the SAGA provided Majority filter for that:

  • http://www.saga-gis.org/saga_tool_doc/2.2.0/grid_filter_6.html
  • http://wiki.awf.forst.uni-goettingen.de/wiki/index.php/Majority_filter