AnsweredAssumed Answered

Checking for ANYNODATA in a DEM always results in True

Question asked by Borgman on Jan 16, 2020
Latest reply on Jan 17, 2020 by Dan_Patterson

I'm working on a script that would fill (NoData) holes in a DEM with a raster calculation. The calculation fills the holes with the average of the surrounding cells and this proces should be repeated to get an accurate result. It works quite well, just the while loop never ends as arcpy.GetRasterProperties_management keeps finding ANYNODATA. Within the DEM itself there is no NoData, but on the outsidesthere is (outside of the extent).

 

The DEM I'm working with is cut (Extract by Mask) to a polygon which I've also set my extent to.

 

Could anyone point me into a direction how I can check for NoData and stop the While loop as soon as the DEM is filled?

 

My script looks like this:

import arcpy

# Environment settings
arcpy.env.overwriteOutput = True
arcpy.env.extent = "D:\..."
arcpy.env.parallelProcessingFactor = "8"
arcpy.env.processorType = "CPU"
DEM = arcpy.Raster("D:\...")

#     Check for NoData in the raster and start filling as long as there is NoData
NoDataCheck = arcpy.GetRasterProperties_management(in_raster=DEM, property_type="ANYNODATA")
NoDataRes = int(NoDataCheck.getOutput(0))
count = 0
print("Voor loop: " + str(NoDataRes))

while NoDataCheck:
     # RasterCalc filling the holes
     expression=' Con(IsNull(DEM), FocalStatistics(DEM, NbrRectangle(5,5, "CELL"), "MEAN"), DEM)'
     arcpy.gp.RasterCalculator_sa(expression, DEM)
     count = count + 1
     NoDataCheck = arcpy.GetRasterProperties_management(in_raster=DEM, property_type="ANYNODATA")
     NoDataRes = int(NoDataCheck.getOutput(0))

Outcomes