ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Building expressions in Raster Calculator

Available with Spatial Analyst license.

  • Example expressions in the Raster Calculator tool dialog box
  • An example Raster Calculator expression in ModelBuilder

When building expressions in the Raster Calculator tool, clicking and double-clicking on the various layers, variables, buttons, and tool names available in the dialog box will help you to avoid syntax errors that may otherwise be made while typing.

Since the expression entered in the Raster Calculator tool will be executed in Python, and Python is case sensitive, it is important to use the correct capitalization of the tool name. For example, to use the IsNull tool, be sure to type it as IsNull, instead of Isnull or isnull.

When multiple Relational or Boolean operators are used in a sequence, the expression requires parentheses. For more information, refer to the usage tips listed in the Raster Calculator tool help.

Example expressions in the Raster Calculator tool dialog box

While Map Algebra is used both in the Raster Calculator and directly in Python, there are some differences in the syntax that you should be aware of.

  • Since there is a specific output parameter in the Raster Calculator tool dialog box, Map Algebra expressions do not include an output name and an equals sign (=) when using the Raster Calculator.
  • Only in the Raster Calculator tool dialog box can layer names be used directly with operators. When working in Python itself, layers must first be cast as Raster objects.
  • Similarly, only in the tool dialog box can Raster Calculator variables be contained within percent signs (%) or quotation marks (").

Raster Calculator tool dialog box examples

Following are several examples of Map Algebra expressions that can be executed in the Raster Calculator tool. In these expressions, the raster layer names are contained within quotes, for example "dist".

  • ("pop" > 150) & ("dist" > 10)
  • (("reclass_rd_dist" * 3) + ("reclass_landuse" * 2) + "reclass_elev") /6.0
  • ("Band4" - "Band3") / Float("Band4" + "Band3")
  • Con("elev" <= 3000, 1, 0)
  • Con(IsNull("elev"),0, "elev")
  • Con(("landuse1" == 1) & ("landuse2" == 5), "landuse1" + "landuse2", 99)
  • Con(Raster('elev') != 0,'elev')
  • (Con('elev', 'elev', "", "elev_feet <> 0")) + Raster("tree_height")
  • Con("inRas" < 45,1, Con(("inRas" >= 45) & ("inRas" < 47),2, Con(("inRas" >= 47)&("inRas" < 49),3, Con("inRas" >= 49,4))))

An example Raster Calculator expression in ModelBuilder

When using the Raster Calculator tool in ModelBuilder, the only difference is that variables can be used as input as well as layers. For more information regarding the syntax, what types of variables can be used, and the connectivity behavior of the Raster Calculator tool in ModelBuilder, see the Raster Calculator tool help.

How variables and layers appear in the expression

The example below shows the Map Algebra expression syntax of a Raster Calculator tool being used in a model.

  • In this example, Raster Dataset Variable (Model Variable), a Long Variable (Model Variable), and a Raster Layer (Layer) are being used.

    Notice that the different variables have slightly different syntax:

    Variable or Layer NameVariable TypeHow syntax first appears in the expression

    Reclass Road

    Raster Dataset Variable"%Reclass Road%"

    Rd weight

    Long Variable%Rd weight%

    Reclass Landuse

    Raster Layer"Reclass Landuse"

    To have inputs be added with the correct syntax

    1. Place the cursor at the appropriate location in the expression box.
    2. Double-click the appropriate Layer or Variable name.

    Raster Calculator tool with expression using variables and layers
    Raster Calculator tool with expression using variables and layers
  • After clicking OK to close the Raster Calculator tool dialog box, a variable representing the "Reclass Landuse" layer will be added to your model as a model variable.

  • When the Raster Calculator tool dialog box is reopened, notice that:

    1. The Reclass Landuse variable is added to the list of Layers and Variables.
    2. The syntax in the expression has been updated from the layer syntax ("Reclass Landuse") to the variable syntax ("%Reclass Landuse%").
    Raster Calculator tool with expression using variables
    Example of Raster Calculator tool with expression using variables

Related Topics

  • How Raster Calculator works
  • Raster Calculator
Feedback on this topic?

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal