Run tools in Map Algebra

Available with Spatial Analyst license.

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 general rules for running Spatial Analyst tools in Map Algebra.

  • A simple Map Algebra expression used 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", "PERCENT_RISE", 3)
    • Example using the Zonal Statistics tool:
      outRas = ZonalStatistics("inzoneraster", "Value", 
                               "invalueraster", "MEAN")
  • Tool names are case sensitive.
    • Example with correct capitalization:
      # The following tools have correct capitalization
      #  and spelling, and are valid.
      outRas = Slope("inraster")
      outRas2 = FocalStatistics("inraster")
    • Incorrect capitalization in the following example will cause an error condition, as both slope and Focalstatistics have invalid capitalization.
      # Correct form is Slope, not slope
      outRas = slope("inraster")
      
      # Correct form is FocalStatistics, not Focalstatistics
      outRas2 = Focalstatistics("inraster", neighborhood)
  • 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"), 10)
    • Example using a Spatial Analyst tool and a non-Spatial Analyst tool:
      # The Result object output from the Buffer 
      #  tool is used as input into the Zonal Statistics tool  
      outRas = ZonalStatistics(arcpy.Buffer_analysis("C:/Data/schools.shp", "#", 500),
                               "OBJECTID", "C:/Data/pop1990", "SUM")

Note:

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

Related topics