<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Iterating using max raster value as criteria to stop model in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/iterating-using-max-raster-value-as-criteria-to/m-p/619595#M20597</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;What I want to do is test the maximum value in the resulting raster and stop the iteration if the max value does not equal -999 (the value in the cells is -999 they need to be changed). &lt;BR /&gt;&lt;BR /&gt;I can't figure out how to make the "while" or "if" iterators work with raster statistics (max cell value).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One way is to write a little Python script using the the Calculate Value tool, the tool output can then be referenced in the While tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression:&amp;nbsp; StopTest(r"%output raster%")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code Block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def StopTest(outRaster):
&amp;nbsp; import arcpy
&amp;nbsp; max = int(arcpy.GetRasterProperties_management (outRaster,"MAX").getOutput(0))
&amp;nbsp; if max == -999:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return True&amp;nbsp; # keep iterating
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return False # time to stop&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Data Type: Boolean&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A less python-heavy approach would be to add the GetRasterProperties tool to the model, connect your raster to it, then connect the GetRasterProperties output to Calculate Value and use this simple python expression instead (no code block needed):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int(%RasterPropertyOut%) == -999&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The downside to this second approach is that if the output of GetRasterProperties is zero, that evaluates to False and the Calculate Value will not run, as its input will be false. Such is the simplicity and elelegance that is ModelBuilder.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 02:27:39 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2021-12-12T02:27:39Z</dc:date>
    <item>
      <title>Iterating using max raster value as criteria to stop model</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/iterating-using-max-raster-value-as-criteria-to/m-p/619593#M20595</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN style="font-size:2;"&gt;I've got a model working as I want. I use the while iterator to keep it going until I can visually see it is time to stop. Then I manually stop it with the Cancel button. In this model, the final output raster is written over the input raster.&lt;BR /&gt;&lt;BR /&gt;What I want to do is test the maximum value in the resulting raster and stop the iteration if the max value does not equal -999 (the value in the cells is -999 they need to be changed). This model takes a raster of &lt;/SPAN&gt;&lt;SPAN&gt;infiltration&lt;/SPAN&gt;&lt;SPAN style="font-size:2;"&gt; rates gained from other sources that are &lt;/SPAN&gt;&lt;SPAN&gt;mosaiced &lt;/SPAN&gt;&lt;SPAN style="font-size:2;"&gt;and then modifies it to fill in "holes" iterating again and again until the holes are filled in. The holes are filled in by using the maximum value surrounding the cell (8 directions). This is not a "fill sinks" issue in a DEM.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can't figure out how to make the "while" or "if" iterators work with raster statistics (max cell value).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thoughts or suggestions?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2013 20:42:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/iterating-using-max-raster-value-as-criteria-to/m-p/619593#M20595</guid>
      <dc:creator>MarkBoucher</dc:creator>
      <dc:date>2013-03-07T20:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating using max raster value as criteria to stop model</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/iterating-using-max-raster-value-as-criteria-to/m-p/619594#M20596</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Perhaps you could clarify your goal...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You say you want to stop the iteration if the max value does not equal -999 &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then you say, the value in the cells is -999 they need to be changed. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;--&amp;gt;&amp;lt;--&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;???&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Mar 2013 14:09:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/iterating-using-max-raster-value-as-criteria-to/m-p/619594#M20596</guid>
      <dc:creator>LT</dc:creator>
      <dc:date>2013-03-09T14:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating using max raster value as criteria to stop model</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/iterating-using-max-raster-value-as-criteria-to/m-p/619595#M20597</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;What I want to do is test the maximum value in the resulting raster and stop the iteration if the max value does not equal -999 (the value in the cells is -999 they need to be changed). &lt;BR /&gt;&lt;BR /&gt;I can't figure out how to make the "while" or "if" iterators work with raster statistics (max cell value).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One way is to write a little Python script using the the Calculate Value tool, the tool output can then be referenced in the While tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression:&amp;nbsp; StopTest(r"%output raster%")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code Block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def StopTest(outRaster):
&amp;nbsp; import arcpy
&amp;nbsp; max = int(arcpy.GetRasterProperties_management (outRaster,"MAX").getOutput(0))
&amp;nbsp; if max == -999:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return True&amp;nbsp; # keep iterating
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return False # time to stop&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Data Type: Boolean&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A less python-heavy approach would be to add the GetRasterProperties tool to the model, connect your raster to it, then connect the GetRasterProperties output to Calculate Value and use this simple python expression instead (no code block needed):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int(%RasterPropertyOut%) == -999&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The downside to this second approach is that if the output of GetRasterProperties is zero, that evaluates to False and the Calculate Value will not run, as its input will be false. Such is the simplicity and elelegance that is ModelBuilder.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:27:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/iterating-using-max-raster-value-as-criteria-to/m-p/619595#M20597</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-12T02:27:39Z</dc:date>
    </item>
  </channel>
</rss>

