<?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 Successive commands within a for loop in arcpy in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/successive-commands-within-a-for-loop-in-arcpy/m-p/1007162#M24945</link>
    <description>&lt;P&gt;Hello, everyone !&lt;/P&gt;&lt;P&gt;I have a list of rasters ('intlist') and for each of them I want to execute succesive commands ('Minus' and 'Con') within a for loop trying to avoid the middle results load and keep only the output rasters from the last command within the loop. I tried the code below but it doesn't return right results, so I would like to ask if there is something that can fix this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;for i in intlist:&lt;BR /&gt;enVr = Minus(i, 260)&lt;BR /&gt;outCon = Con(enVr, enVr, 0, "Value &amp;gt;= 0")&lt;BR /&gt;name = "C:/MSc_thesis/int/" + "en{}".format(i)&lt;BR /&gt;outCon.save(name)&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Sat, 05 Dec 2020 15:11:15 GMT</pubDate>
    <dc:creator>CamiSunley</dc:creator>
    <dc:date>2020-12-05T15:11:15Z</dc:date>
    <item>
      <title>Successive commands within a for loop in arcpy</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/successive-commands-within-a-for-loop-in-arcpy/m-p/1007162#M24945</link>
      <description>&lt;P&gt;Hello, everyone !&lt;/P&gt;&lt;P&gt;I have a list of rasters ('intlist') and for each of them I want to execute succesive commands ('Minus' and 'Con') within a for loop trying to avoid the middle results load and keep only the output rasters from the last command within the loop. I tried the code below but it doesn't return right results, so I would like to ask if there is something that can fix this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;for i in intlist:&lt;BR /&gt;enVr = Minus(i, 260)&lt;BR /&gt;outCon = Con(enVr, enVr, 0, "Value &amp;gt;= 0")&lt;BR /&gt;name = "C:/MSc_thesis/int/" + "en{}".format(i)&lt;BR /&gt;outCon.save(name)&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Dec 2020 15:11:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/successive-commands-within-a-for-loop-in-arcpy/m-p/1007162#M24945</guid>
      <dc:creator>CamiSunley</dc:creator>
      <dc:date>2020-12-05T15:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: Successive commands within a for loop in arcpy</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/successive-commands-within-a-for-loop-in-arcpy/m-p/1007163#M24946</link>
      <description>&lt;P&gt;can you post the full code?&lt;/P&gt;&lt;P&gt;A quick first guess would be that theres no format specified in the string, theres also no need to combine + with .format&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;name = "C:/MSc_thesis/int/en{}.tif".format(i)&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 05 Dec 2020 15:33:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/successive-commands-within-a-for-loop-in-arcpy/m-p/1007163#M24946</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-12-05T15:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Successive commands within a for loop in arcpy</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/successive-commands-within-a-for-loop-in-arcpy/m-p/1007164#M24947</link>
      <description>&lt;P&gt;Here is another option of saving the output.. The names are saved correctly, but the output it's not right concerning the calculations as there are still Values &amp;lt;0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = "C:/MSc_thesis"&lt;/P&gt;&lt;P&gt;intlist&amp;nbsp; = arcpy.ListRasters("*", "TIF")&lt;/P&gt;&lt;P&gt;f = 260&lt;/P&gt;&lt;P&gt;for i in intlist:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;enVr = Minus(i, f)&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;&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;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;outCon = Con(enVr, enVr, 0, "Value &amp;gt;= 0")&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;outCon.save(os.path.join(arcpy.env.workspace,"en" + str(i)))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Dec 2020 15:56:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/successive-commands-within-a-for-loop-in-arcpy/m-p/1007164#M24947</guid>
      <dc:creator>CamiSunley</dc:creator>
      <dc:date>2020-12-05T15:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Successive commands within a for loop in arcpy</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/successive-commands-within-a-for-loop-in-arcpy/m-p/1007176#M24948</link>
      <description>&lt;P&gt;isn't the return value of ListRasters a string? i.e. intlist is a list of string names of the raster, not Raster Objects.&lt;/P&gt;&lt;P&gt;I'd say to cast the raster into an object with ras_object = arcpy.Raster(i)&lt;/P&gt;&lt;P&gt;i may even just be the name and not the path, whereby you would have to get the raster path with something like path = os.path.join(&lt;SPAN&gt;arcpy.env.workspace, i)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ras_object = arcpy.Raster(path)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Dec 2020 19:17:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/successive-commands-within-a-for-loop-in-arcpy/m-p/1007176#M24948</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-12-05T19:17:41Z</dc:date>
    </item>
  </channel>
</rss>

