Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If you have produced a long list of rasters (lets say 50) and want to add them together, is there any shorter way to write in python rather than typing all the inputs, like so:

outRas = inRas1 + inRas2.........+ inRas50
share|improve this question

You can make a list of the raster names you wish to add together, then step through the list, adding each one to an output raster.

import arcpy
from arcpy import env

# Set the current workspace
env.workspace = "C:/Data/DEMS"

#Check out ArcGIS Spatial Analyst extension license

# Get a list of ESRI GRIDs from the workspace and print

rasterList = arcpy.ListRasters("*", "GRID")

#Step through the list of raster names
for rasname in rasterList:
    #Cast rasname as raster before adding
    listras = Raster(rasname)
    #Add each raster to an output raster.
    #The previous step of casting as a Raster will invoke
    #the Spatial Analyst Addition function.
    outras += listras

#Save output Raster"C:/temp/outras")
share|improve this answer
Another possibility, once you have a list of rasters, is to use CellStatistics with the "SUM" option. – blah238 Aug 22 '12 at 18:03
I got what your suggestion. But, what if I have other rasters in my workspace and don't want to add them? – tdr Aug 22 '12 at 18:32
Because you have had the foresight to number the raster datasets systematically, simply create the list of raster names with a small loop. Alternatively, filter rasterList to exclude any raster you do not want to process. – whuber Aug 22 '12 at 18:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.