Select to view content in your preferred language

Fill Raster holes with nearest neighbour

9044
5
Jump to solution
07-04-2021 06:48 AM
Daniel2
Emerging Contributor

Hello,

one of the raster files I base my weighted overlay analysis on has NODATA values or white spaces (see pictures).holesinraster.png I would like to fill these holes with new cells with values corresponding to the cells surrounding them. I was a thinking maybe some kind of nearest neighbor method or create new cells based on the mean values from the surrounding cells. I found some method here in the forum where the tool "Con" was used, but I don't know how to correctly implement it. Are there other tools I can use or workflows with which I can fix my Raster? 

Thank you in advance and best wishes

Daniel

0 Kudos
2 Solutions

Accepted Solutions
JayantaPoddar
MVP Alum

Please check if a similar expression works for you using Raster Calculator?

 

Con(IsNull("raster"), FocalStatistics("raster", NbrRectangle(5,5, "CELL"), "MEDIAN"), "raster")

You could change the 5,5 rectangle size to a bigger one (e.g. 9,9)

 

 



Think Location

View solution in original post

JuanLaguna
Esri Contributor

Hi Daniel2.

The Nibble tool from Spatial Analyst can be applied to your problem.

Replaces cells of a raster corresponding to a mask with the values of the nearest neighbors.

https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/nibble.htm

 

This tool allows specific areas of a raster to be replaced by the value of their nearest neighbour. These areas are defined by a mask input. In the mask input, cells that are NoData define which cells will be processed, or "nibbled away".

In your case, the areas you want to replace are already NoData, so you can actually just use the same dataset as both the input and the mask raster. You will just need to change one of the parameters from its default setting.

Run the Nibble tool as follows:

JuanLaguna_1-1625822864535.png

 

Starting out with your input here:

Holes_figures_input.png

 

The result is:

Holes_figures_output.png


Hopefully this will be a useful solution for you.

 

Of course, be mindful of how the results are used. The premise of using the nearest neighbour to a replace the value of an existing cell works well on a proximal basis. However, as the distances increase, the connection may become more tenuous, and the results more questionable.

Your example illustrates this point well. For the single cells and small clusters of cells, the new values in the output appear to be very reasonable. For the larger rectangular areas, this may not be the case.


Cheers,
Juan Laguna
Spatial Analyst Team





 

View solution in original post

5 Replies
JayantaPoddar
MVP Alum

Please check if a similar expression works for you using Raster Calculator?

 

Con(IsNull("raster"), FocalStatistics("raster", NbrRectangle(5,5, "CELL"), "MEDIAN"), "raster")

You could change the 5,5 rectangle size to a bigger one (e.g. 9,9)

 

 



Think Location
Daniel2
Emerging Contributor

Thank you so much! It worked really well. I was breaking my head about this!

0 Kudos
PrasadiSenadeera
New Contributor

Thank you very much 

0 Kudos
JuanLaguna
Esri Contributor

Hi Daniel2.

The Nibble tool from Spatial Analyst can be applied to your problem.

Replaces cells of a raster corresponding to a mask with the values of the nearest neighbors.

https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/nibble.htm

 

This tool allows specific areas of a raster to be replaced by the value of their nearest neighbour. These areas are defined by a mask input. In the mask input, cells that are NoData define which cells will be processed, or "nibbled away".

In your case, the areas you want to replace are already NoData, so you can actually just use the same dataset as both the input and the mask raster. You will just need to change one of the parameters from its default setting.

Run the Nibble tool as follows:

JuanLaguna_1-1625822864535.png

 

Starting out with your input here:

Holes_figures_input.png

 

The result is:

Holes_figures_output.png


Hopefully this will be a useful solution for you.

 

Of course, be mindful of how the results are used. The premise of using the nearest neighbour to a replace the value of an existing cell works well on a proximal basis. However, as the distances increase, the connection may become more tenuous, and the results more questionable.

Your example illustrates this point well. For the single cells and small clusters of cells, the new values in the output appear to be very reasonable. For the larger rectangular areas, this may not be the case.


Cheers,
Juan Laguna
Spatial Analyst Team





 

Daniel2
Emerging Contributor

Hi Juan,

I'll try that method as well, thank you for the detailed answer! Yes I'm aware of the possible inaccuracies and will discuss that in my thesis. I think it won't be such a big issue tho. The data I'm using is the noise level of streets and in the shown hole areas are mostly buildings, so the noise "moves" rather linear from the streets to the surrounding areas.

Cheers
Daniel

0 Kudos