Showing results for 
Search instead for 
Do you mean 

Replace NoData locations with the value of their nearest neighbor

by Technical Evangelist on ‎03-07-2019 12:13 PM - edited on ‎02-24-2020 03:38 AM by Community Manager (932 Views)

Download model


Left view shows the original thematic image with DN 0 (color black), the right View shows the results of filling with the nearest neighbor


This Spatial Model replaces NoData locations with the value of their nearest (non-NoData) neighbor. This is useful for filling areas of a raster where the data is known to be erroneous.




The model will take an Input Raster which should be a single band thematic image. This image could already have NoData locations defined and if this is the case the Set Zero to NoData? flag should be set to False. However if Input Raster has the locations of unknown data defined as a DN value of 0 then the  Set Zero to NoData? flag should be set to True. The NoData locations will be filled with new values based on the closest (nearest neighbor) pixel with a valid (non-NoData) value. Note that if a different DN value is being used to represent background or unknown value locations (e.g. 255) then the model will need to be edited to specify that value on the Set to NoData operator.


In addition a second input raster can be specified on the Set Mask to NoData (Optional) port. This enables another raster to be used to specify additional unknown value locations that should be filled. Any mask data pixel locations with a DN value of 0 or NoData will be used to set the additional NoData locations on the Input Raster data. The input can be left blank if no additional mask is desired. Note that if a mask image is used care should be taken to ensure the desired boundary is output - the model will default to process the intersection of the two input rasters and so may require modification in some circumstances.


The Maximum Distance in Pixels (Optional) port  determines the maximum distance into any NoData voids that the process fills with the nearest neighbor value. For example, if there was a circular NoData gap with a diameter of 30 pixels and the Maximum Distance specified was set to 10 pixels, the resulting output image would still contain a circular NoData hole but reduced to a diameter of 10 pixels. A Maximum Distance of 15 would be required to completely fill the original NoData hole. Since you may not know the necessary distance required to completely fill all NoData holes this port can be left blank and all holes will be filled. 


The following Spatial Model article provides an alternative approach to filling holes using Focal Majority rather than Proximity Spread:


...and this one fills holes using interpolation (so is suitable for athemtic data, not thematic):


Input parameters: 


See above for description of the following options







on ‎10-13-2020 05:27 AM

Is it possible to replace nodata pixel with an average value of the Neighbor values?


by Technical Evangelist
on ‎10-13-2020 05:50 AM



Absolutely. You can use this approach


Or this one


Or implement a totally new one. There's an Interpolate Using IDW operator now which would be ideal.