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:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># Environment settings</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>extent <SPAN class="operator token">=</SPAN> <SPAN class="string token">"D:\..."</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>parallelProcessingFactor <SPAN class="operator token">=</SPAN> <SPAN class="string token">"8"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>processorType <SPAN class="operator token">=</SPAN> <SPAN class="string token">"CPU"</SPAN>
DEM <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"D:\..."</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Check for NoData in the raster and start filling as long as there is NoData</SPAN>
NoDataCheck <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetRasterProperties_management<SPAN class="punctuation token">(</SPAN>in_raster<SPAN class="operator token">=</SPAN>DEM<SPAN class="punctuation token">,</SPAN> property_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"ANYNODATA"</SPAN><SPAN class="punctuation token">)</SPAN>
NoDataRes <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>NoDataCheck<SPAN class="punctuation token">.</SPAN>getOutput<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
count <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Voor loop: "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>NoDataRes<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">while</SPAN> NoDataCheck<SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># RasterCalc filling the holes</SPAN>
expression<SPAN class="operator token">=</SPAN><SPAN class="string token">' Con(IsNull(DEM), FocalStatistics(DEM, NbrRectangle(5,5, "CELL"), "MEAN"), DEM)'</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>gp<SPAN class="punctuation token">.</SPAN>RasterCalculator_sa<SPAN class="punctuation token">(</SPAN>expression<SPAN class="punctuation token">,</SPAN> DEM<SPAN class="punctuation token">)</SPAN>
count <SPAN class="operator token">=</SPAN> count <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN>
NoDataCheck <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetRasterProperties_management<SPAN class="punctuation token">(</SPAN>in_raster<SPAN class="operator token">=</SPAN>DEM<SPAN class="punctuation token">,</SPAN> property_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"ANYNODATA"</SPAN><SPAN class="punctuation token">)</SPAN>
NoDataRes <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>NoDataCheck<SPAN class="punctuation token">.</SPAN>getOutput<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>