Run tools in map algebra

Map algebra provides a rich suite of tools for performing comprehensive, raster-based spatial analysis and modeling. Map algebra expressions can consist of a single tool or operator but can also consist of multiple tools and operators. Complex map algebra expressions can be made up of Spatial Analyst tools but can also include tools from other toolboxes.

Rules for running tools

The following are some general rules for running Spatial Analyst tools in map algebra successfully.

Simple expressions

A simple map algebra expression to run a single tool includes the tool name followed by the input dataset and the tool parameters within parentheses.

Example using the Slope tool:

``outRas = Slope("elevation.tif", "PERCENT_RISE", 3)``

Example using the Zonal Statistics tool with two input rasters:

``````outRas = ZonalStatistics("inzoneraster.tif", "Value",
"invalueraster.tif", "MEAN")``````

Tool names and casing

Tool names are case sensitive. Incorrect capitalization will cause an error condition.

Example with correct capitalization:

``````# The following tools have correct capitalization
#  and spelling, and are valid.
outRas = Square("inraster.tif")
outRas2 = GreaterThan("inraster.tif", "inraster2.tif")``````

Examples of incorrect capitalization:

``````# The following is invalid because the tool name starts with a capital letter.
outRas = square("inraster")

# The following is invalid because the tool name is capitalized incorrectly.
outRas2 = Greaterthan("inraster", "inraster2")``````
Note:

As with all tools in the Python window, if you select the tool name in the automatic completion selection list, the automatic completion will correct the capitalization for the tool name.

Complex expressions

You can embed a tool in another tool to create complex expressions. Complex expressions can consist of multiple Spatial Analyst tools but can also include tools from other toolboxes.

Example using two Spatial Analyst tools:

``````# Complex expression using two Spatial Analyst tools
outRas = Slice(Slope("C:/Data/elevation.tif"), 10)``````

Example using a Spatial Analyst tool and a non-Spatial Analyst tool:

``````# The Result object output from the Buffer tool
#  is used as the zone input for the Zonal Statistics tool
outRas = ZonalStatistics(arcpy.Buffer_analysis("C:/Data/schools.shp", "#", 500),
"OBJECTID", "C:/Data/pop1990.tif", "SUM")``````

Related topics

In this topic
1. Rules for running tools