Layer: use the fill no-data algorithm to remove holes in the raster
Currently, we use the fill no-data algorithm for a particular use case in elevation layers: the removal of steep walls at the edge of no-data regions. See the cog_nodata
example for that.
However, with a bit of tweaking, this algorithm can be used also to remove (small) holes in layers.
The current algorithm is rather simple and does the following thing:
- For any given pixel of the texture, determine if it is a valid value or a no-data value. If it is a valid value, just use it.
- If it is a no-data value, loop over a downsampled version of the texture and find the nearest valid pixel, and use its color as value.
- Replace the alpha component of the pixel with zero, to indicate to the fragment shader that it must be discarded.
Here are the tweaks needed to make it useable in any layer:
- Specify a replacement value for the alpha channel (rather than forcing it to zero). For example, to fill holes in a raster, we must put an alpha at 1 rather than zero.
- Specify a maximum radius for the algorithm, so that only holes smaller than a threshold are filled, and other are kept intact. This is useful if the user wants to remove small holes and keep the external boundaries of the raster as is.