I have a raster with gaps in it and want to fill the gaps with the mean of the surrounding cells using focal statistics. I found the code to achieve this here Fill in NoData gaps in raster using ArcGIS for Desktop?

I then want to take the output from the focal statistics and repeat about 15 times in order to expand the raster.

I have managed to get it to work somewhat but it stops after about 3 iterations

arcpy.env.workspace= r'C:\Users\Environmental\Tides\Analysis\Analysis.gdb'

arcpy.env.overwriteOutput = True 

Waves = arcpy.sa.Con(arcpy.sa.IsNull("M2_reproj.tif"),arcpy.sa.FocalStatistics("M2_reproj.tif",arcpy.sa.NbrCircle(1),'MEAN'), "M2_reproj.tif")

seq = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]

for num in seq:
    Waves = arcpy.sa.Con(arcpy.sa.IsNull("Waves"),arcpy.sa.FocalStatistics("Waves",arcpy.sa.NbrCircle(1),'MEAN'), "Waves") 
  • 1
    do you get an error when the code stops or does it say it was executed successfully?
    – NULL.Dude
    Oct 11, 2017 at 15:36
  • there is no error, it seems to execute correctly but the raster has only expanded by 3 cells Oct 11, 2017 at 15:42
  • How are you running this?You set the work space to a geodatabase but then you reference tiff files
    – Hornbydd
    Oct 11, 2017 at 22:10
  • If I understand the question correctly, I'm running this in the python window Oct 12, 2017 at 8:05
  • In relation to setting the workspace, if I don't set the workspace to a geodatabase for some reason the code doesn't work properly? I then save the files as tiffs as if i don't i get an error that the file can't be found Oct 12, 2017 at 8:18


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.