<?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: sum rasters in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sum-rasters/m-p/408837#M32210</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In case some one else is doing this I have ended up just using SUM in cell statistics. I convert the category I am interested in to a binary and then sum. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What I really wanted though was to be able to have various classes assigned and to add them depending on what class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;e.g.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If cell = 6 then convert is to a 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if cell = anything but 6 convert it to 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then sum rasters to produce an output image with the frequency of that category&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and then repeat this for each other category.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if cell =5 then convert to a 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else convert to 0 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and sum&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 27 Jun 2011 21:54:14 GMT</pubDate>
    <dc:creator>SarahBurns</dc:creator>
    <dc:date>2011-06-27T21:54:14Z</dc:date>
    <item>
      <title>sum rasters</title>
      <link>https://community.esri.com/t5/python-questions/sum-rasters/m-p/408836#M32209</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I posted this to spatial analyst but thought it might be more appropriate here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have reclassified many raster to be only 0's and 1's and I would like to sum the 1's together and output a new raster which is basically a count of those rasters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have used the code from a thread in spatial analyst so I am open to different tools to do this processing. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When I run the code I do receive an output but it is wrong and python keeps crashing each time I try to run it so I don't receive an error message. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Can someone please tell me what I am doing wrong.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
import os

# Set environment settings
arcpy.env.workspace = "D:/sumrasters/rasterimgs"
outputfolder="D:/sumrasters/output_sumRaster"
datapath="D:/reclass/sumrasters/rasterimgs"
arcpy.env.overwriteOutput = 1
arcpy.CheckOutExtension('Spatial')
arcpy.env.scratchWorkspace = r"c:\temp\scratch.gdb"


#create a list of rasters in the workspace
rasters = arcpy.ListRasters("*","IMG")

i = 0
#loop through rasters in list
for raster in rasters:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print rasters
&amp;nbsp;&amp;nbsp;&amp;nbsp; #sum rasters together
&amp;nbsp;&amp;nbsp;&amp;nbsp; if i == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outSUM = arcpy.Raster(raster)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outSUM = outSUM + raster
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 0

#save final output to the current workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; outSUM.save(os.path.join(outputfolder,"sumRas.img"))

print "end of processing"
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jun 2011 01:13:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-rasters/m-p/408836#M32209</guid>
      <dc:creator>SarahBurns</dc:creator>
      <dc:date>2011-06-21T01:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: sum rasters</title>
      <link>https://community.esri.com/t5/python-questions/sum-rasters/m-p/408837#M32210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In case some one else is doing this I have ended up just using SUM in cell statistics. I convert the category I am interested in to a binary and then sum. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What I really wanted though was to be able to have various classes assigned and to add them depending on what class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;e.g.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If cell = 6 then convert is to a 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if cell = anything but 6 convert it to 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then sum rasters to produce an output image with the frequency of that category&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and then repeat this for each other category.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if cell =5 then convert to a 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else convert to 0 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and sum&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Jun 2011 21:54:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-rasters/m-p/408837#M32210</guid>
      <dc:creator>SarahBurns</dc:creator>
      <dc:date>2011-06-27T21:54:14Z</dc:date>
    </item>
  </channel>
</rss>

