<?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: Raster Calculator Expression used during iteration loop in ArcGIS Spatial Analyst Questions</title>
    <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/raster-calculator-expression-used-during-iteration/m-p/660511#M9530</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you using ModelBuilder and just exporting the script for us to see?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you're working Python, arcpy map algebra is a lot easier to work with.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example instead of &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.gp.RasterCalculator_sa("SetNull(~IsNull("%End_Pts_Raster%"), \"%Least_Cost_Path%\")", Least_Cost_Route)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the arcpy map algebra equivalent is something like this. Note how easy it is to save your rasters using the count variable to uniquely named grids with the .save() method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;from arcpy.sa import * while .... &amp;nbsp;&amp;nbsp;&amp;nbsp; ... &amp;nbsp;&amp;nbsp;&amp;nbsp; eptras = Raster(End_Pts_Raster) &amp;nbsp;&amp;nbsp;&amp;nbsp; LCostPth = Raster(Least_Cost_Path) &amp;nbsp;&amp;nbsp;&amp;nbsp; LCR = SetNull( ~ IsNull(eptras), LCostPth) &amp;nbsp;&amp;nbsp;&amp;nbsp; LCR.save("lcr{0}".format(count) &amp;nbsp;&amp;nbsp;&amp;nbsp; count -= 1&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00p600000002000000" rel="nofollow" target="_blank"&gt;Desktop 10.1 Help: What is Map Algebra&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Apr 2014 01:33:11 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2014-04-25T01:33:11Z</dc:date>
    <item>
      <title>Raster Calculator Expression used during iteration loop</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/raster-calculator-expression-used-during-iteration/m-p/660510#M9529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I was wondering if someone can help with the following Raster Calculator Expression.&amp;nbsp; I am trying to calculate the output least cost path raster to "null" where the end points overlap full least cost path raster.&amp;nbsp; Additionally I am trying to use in -line variable substitution in the expression as the following snippet iterates 3 times.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope I have made sense.&amp;nbsp; I appreciate any suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Entire function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Process: Cost Distance &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.CostDistance_sa(destValue, weighted_Raster, "distance_Raster", "", 'backlink_Raster')&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Cost Path &amp;nbsp;&amp;nbsp;&amp;nbsp; Least_Cost_Path = arcpy.gp.CostPath_sa(originValue,"distance_Raster", "backlink_Raster", os.path.join(savepath + "\\Results.gdb" + "\\lcp_" + str(count)), "EACH_CELL", "OBJECTID")&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; global count&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; while count &amp;lt; 3:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Local variables: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End_Pts = 'End_Pts' &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Output_polyline_features = 'Output_polyline_features' &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End_Pts_Raster = 'End_Pts_Raster' &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Least_Cost_Route = 'Least_Cost_Route' &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Reclass_rast1 = 'Reclass_rast1'&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Raster to Polyline &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RasterToPolyline_conversion(Least_Cost_Path, Output_polyline_features, "ZERO", "0", "SIMPLIFY", "")&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Feature Vertices To Points &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureVerticesToPoints_management(Output_polyline_features, End_Pts, "BOTH_ENDS")&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Point to Raster &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.PointToRaster_conversion(End_Pts, "", End_Pts_Raster, "MOST_FREQUENT", "NONE", Least_Cost_Path)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Raster Calculator &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.RasterCalculator_sa("SetNull(~IsNull("%End_Pts_Raster%"), \"%Least_Cost_Path%\")", Least_Cost_Route)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Set null statement:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.RasterCalculator_sa("SetNull(~IsNull("%End_Pts_Raster%"), \"%Least_Cost_Path%\")", Least_Cost_Route)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 20:53:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/raster-calculator-expression-used-during-iteration/m-p/660510#M9529</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2014-04-22T20:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Raster Calculator Expression used during iteration loop</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/raster-calculator-expression-used-during-iteration/m-p/660511#M9530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you using ModelBuilder and just exporting the script for us to see?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you're working Python, arcpy map algebra is a lot easier to work with.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example instead of &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.gp.RasterCalculator_sa("SetNull(~IsNull("%End_Pts_Raster%"), \"%Least_Cost_Path%\")", Least_Cost_Route)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the arcpy map algebra equivalent is something like this. Note how easy it is to save your rasters using the count variable to uniquely named grids with the .save() method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;from arcpy.sa import * while .... &amp;nbsp;&amp;nbsp;&amp;nbsp; ... &amp;nbsp;&amp;nbsp;&amp;nbsp; eptras = Raster(End_Pts_Raster) &amp;nbsp;&amp;nbsp;&amp;nbsp; LCostPth = Raster(Least_Cost_Path) &amp;nbsp;&amp;nbsp;&amp;nbsp; LCR = SetNull( ~ IsNull(eptras), LCostPth) &amp;nbsp;&amp;nbsp;&amp;nbsp; LCR.save("lcr{0}".format(count) &amp;nbsp;&amp;nbsp;&amp;nbsp; count -= 1&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00p600000002000000" rel="nofollow" target="_blank"&gt;Desktop 10.1 Help: What is Map Algebra&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2014 01:33:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/raster-calculator-expression-used-during-iteration/m-p/660511#M9530</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-04-25T01:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: Raster Calculator Expression used during iteration loop</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/raster-calculator-expression-used-during-iteration/m-p/660512#M9531</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Map algebra tools were used in my solution.&amp;nbsp; Thanks Curtis! Here is what worked for me...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Returns a value of 1 where End_Raster is NoData and 0 End_Raster points.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; isNull1 = IsNull(End_Raster)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; isNull1.save("isNull1_{0}".format(count))

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Returns LCP minus the end points
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; setNull1 = SetNull(isNull1,get_LCP(count),"Value = 0")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; setNull1.save("setNull1_{0}".format(count))
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:56:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/raster-calculator-expression-used-during-iteration/m-p/660512#M9531</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2021-12-12T03:56:46Z</dc:date>
    </item>
  </channel>
</rss>

