<?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: Struggling with seemingly simple RasterList and sum script: please HELP! in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471193#M36764</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Dan, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried the Cell Statistics with the same result.&amp;nbsp; One thing that's interesting to me is that I can't get the SomaExp line to print in order to determine if that line is working and I'm uncertain how to figure out just where exactly this code is breaking. Also, I am testing this code on a small sub-sample (only 8 grids that are under 2mb in total size).&amp;nbsp; Please see revised code (thanks to guidance from Rick Momsen):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Script to list each output raster and sum them&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcgisscripting, time&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#set up &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.workspace = "C:\\test\\results"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputFolder = "C:\\test\\final"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasterList = gp.ListRasters("","GRID")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; somaExp = " "&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for raster in rasterList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; somaExp = somaExp + raster + ";"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print somaExp&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gpsa = outputFolder + "\\" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CellStatistics_sa(somaExp[:-1], gpsa, "SUM")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;except:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Nice try, but it didn't work." &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; time.sleep(15)&amp;nbsp; #give's you time to see the error &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Finally, I found reference in the forums to version issues of python and arcGIS, and wonder if I may be having issues importing arcscripting.&amp;nbsp; I'm uncertain how to check if the import is working or not. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for any advice or thoughts.&amp;nbsp; ALL are appreciated and helping me to get caught up on Python.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 10 Apr 2011 17:09:27 GMT</pubDate>
    <dc:creator>AlisterFenix</dc:creator>
    <dc:date>2011-04-10T17:09:27Z</dc:date>
    <item>
      <title>Struggling with seemingly simple RasterList and sum script: please HELP!</title>
      <link>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471191#M36762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I???ve gotten quite rusty on my Python over the years and have&amp;nbsp; now been stuck on a seemingly easy little script for far too long, and have officially reached the reaching out point.&amp;nbsp; Hopefully some python guru???s out there will be able to see what I???m doing wrong and point me in the right direction.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Quick background: I???ve created a complex model whose output is a number of grids (will be in the order of over a thousand).&amp;nbsp; I now simply need to sum all of the grids together as my final output before I can complete the analysis.&amp;nbsp; Obviously, when you have over a thousand grids the option of manually adding names within raster calculator (or anywhere else for that matter) becomes obsolete.&amp;nbsp; So, here???s the script for listing the output rasters and summing them:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-----------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Script to list each output raster and sum them&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#create the geoprocessor object&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#check out any necessary licenses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#set up the local variables...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.workspace = "C:\\test\\results"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputFolder = "C:\\test\\final"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasterList = gp.ListRasters("","GRID")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print rasterList&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raster = rasterList.next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print raster&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; somaExp = " "&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while raster:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; soma = somaExp + raster + "+"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print somaExp&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raster = rasterList.next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gpsa = outputFolder + "\\" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SingleOutputMapAlgebra_sa(soma[:-1], gpsa)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#In the rare case that this script does not work...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;except:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Nice try, but it didn't work."&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;---------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The ListRasters is working (although it is putting a ???u??? in front of the names), but I can???t get any other clues about why it keeps crashing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I???m running ArcGIS 9.3 and python 2.5.1 on Windows XP.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance for any help!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Analisa&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Apr 2011 00:36:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471191#M36762</guid>
      <dc:creator>AlisterFenix</dc:creator>
      <dc:date>2011-04-10T00:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with seemingly simple RasterList and sum script: please HELP!</title>
      <link>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471192#M36763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;did you rule out cell statistics with the sum option?&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=6283&amp;amp;pid=6281&amp;amp;topicname=Cell_Statistics"&gt;http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=6283&amp;amp;pid=6281&amp;amp;topicname=Cell_Statistics&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;You may be running into problems if the grid list is too long, in which case, you may need to do it incrementally&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Apr 2011 10:31:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471192#M36763</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2011-04-10T10:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with seemingly simple RasterList and sum script: please HELP!</title>
      <link>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471193#M36764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Dan, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried the Cell Statistics with the same result.&amp;nbsp; One thing that's interesting to me is that I can't get the SomaExp line to print in order to determine if that line is working and I'm uncertain how to figure out just where exactly this code is breaking. Also, I am testing this code on a small sub-sample (only 8 grids that are under 2mb in total size).&amp;nbsp; Please see revised code (thanks to guidance from Rick Momsen):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Script to list each output raster and sum them&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcgisscripting, time&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#set up &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.workspace = "C:\\test\\results"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputFolder = "C:\\test\\final"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasterList = gp.ListRasters("","GRID")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; somaExp = " "&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for raster in rasterList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; somaExp = somaExp + raster + ";"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print somaExp&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gpsa = outputFolder + "\\" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CellStatistics_sa(somaExp[:-1], gpsa, "SUM")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;except:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Nice try, but it didn't work." &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; time.sleep(15)&amp;nbsp; #give's you time to see the error &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Finally, I found reference in the forums to version issues of python and arcGIS, and wonder if I may be having issues importing arcscripting.&amp;nbsp; I'm uncertain how to check if the import is working or not. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for any advice or thoughts.&amp;nbsp; ALL are appreciated and helping me to get caught up on Python.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Apr 2011 17:09:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471193#M36764</guid>
      <dc:creator>AlisterFenix</dc:creator>
      <dc:date>2011-04-10T17:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with seemingly simple RasterList and sum script: please HELP!</title>
      <link>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471194#M36765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;haven't used it in a while but is there a need to build the soma line?&amp;nbsp; I got the impression from the help file for 9.3 that you just needed to pass on a list of grids which you already have in your rasterList variable...could be wrong, but it would only seem logical unless the ListRasters doesn't provide a list formatted properly for use in subsequent SA tools.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Apr 2011 19:32:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471194#M36765</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2011-04-10T19:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with seemingly simple RasterList and sum script: please HELP!</title>
      <link>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471195#M36766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This code should work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rasterList = gp.ListRasters("","GRID")
somaExp = "" #note that your code had somaExp = " " (and extra space)
for raster in rasterList:
&amp;nbsp;&amp;nbsp; somaExp = somaExp + raster + " + " #Note the SOMA language requires single spaces around the operations, so your "+" would be invalid 
gpsa = outputFolder + "\\output" #Note in your code you were only naming the folder
gp.SingleOutputMapAlgebra_sa(soma[:-3], gpsa) #Note the [:-3] index&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:51:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/struggling-with-seemingly-simple-rasterlist-and/m-p/471195#M36766</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T20:51:13Z</dc:date>
    </item>
  </channel>
</rss>

