Replace null values within a raster using statistical information from the surrounding data values

08-23-2017 01:13 PM
Occasional Contributor

I am attempting to use this method to interpolate currently null values in a raster: How To: Remove and replace no data values within a raster using statistical information from the sur... 

This code is not working in raster calculator for Desktop 10.5. Is there a syntax update that I am missing?

Con(IsNull("raster"), FocalStatistics("raster", NbrRectangle(5,5, "CELL"), "MEAN"), "raster")
0 Kudos
6 Replies
MVP Esteemed Contributor

is your raster called 'raster'?

and if the gap is too big, it won't fill in in any event, you have to use Nibble (same in ArcMap and in Pro)

Occasional Contributor

My raster is called "m1sm_degnull". This is the code I tried in raster calculator:

    FocalStatistics("m1sm_degnull", NbrCircle(15,15, "CELL"), "MEAN"),

This is the error I recieved:

ERROR 000539: Error running expression: rcexec()
Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 5, in rcexec
TypeError: __init__() takes at most 3 arguments (4 given)

Failed to execute (RasterCalculator).

Hmm, I'll look into Nibble. That may be just what I'm looking for (as I do have a large gap). Thanks a bunch! 

0 Kudos
MVP Esteemed Contributor
Con(IsNull("m1sm_degnull", FocalStatistics("m1sm_degnull", NbrCircle(15,15, "CELL",""), "MEAN", ""), "m1sm_degnull")

you had a bracket in the wrong place and just to be sure I put the extra "" parameter in FocalStatistics

0 Kudos
MVP Esteemed Contributor

I guess I disagree, the syntax looks correct to me. I would double check to make sure these layer names are absolutely correctly specified -- by erasing the expression and rebuilding it using the Raster Calculator expression builder buttons. (Note, I reformatted your code to make it easier to read.)

Nibble only works on integer data, just so you know. With float data, multiple runs of Focal Statistics may be the best way to roll it. I think Esri should write us a hole-filling tool!

Esri Regular Contributor

I would convert the raster to points and then interpolate.

If you use an exact interpolator set the cell size and extent equal to the raster you want to fill.

With an inexact interpolator you'll have to use CON to replace the NoData.


Occasional Contributor

I like this idea. Thanks. I was working with 10m elevation data that ended up having some odd values, seemingly an artifact of raster resolution and steep embankments along a roadway in mountainous terrain. I ended up setting likely extraneous values to nulls and was hoping to interpolate the values of these cells to smooth the DEM along the roadway.