[GIS] Raster Calculator Iteration in ModelBuilder

arcgis-desktoparcpyiteratormodelbuilderraster-calculator

I have a large number of rasters and I want to add 1 to each of them (e.g. each raster's values currently range from 0 to 1, and I want to make them range from 1 to 2). I believe ModelBuilder, using the "Iterate Rasters" tool and the "Raster Calculator" tool, should do this.

In "Raster Calculator" outside of modelbuilder, selecting the raster name and typing + 1 works to do this on a single raster. However, in modelbuilder, using ("%Raster%") + 1 does not work (see attached photo).

I'm new to ModelBuilder and Python.

Model_to_be_fixed

Best Answer

The easiest solution is to replace the raster calculator with the "Plus" operator in the iterator.

EDIT: note that I wasn't able to reproduce the problem in ArcGIS 10.6:

("%Raster%") + 1

worked fine in my iterator ( with output =, for example, %Raster%_out )

Anyway, the best solution is to use a Python script

import arcpy 
from arcpy.sa import *

arcpy.env.workspace = r'your_path_to_directory'
for r in arcpy.ListRasters("*"): # list all rasters in workspace
    outRaster = Raster(r)+1 #perfoms addition
    outRaster.save(r[:-4] + "out.tif") #save output in tif format