Skip to main content

Arithmetic

Summary

Performs an arithmetic operation between two rasters or between a raster and a scalar and returns a raster object with the operation applied.

Discussion

For more information about how this function works, see the Arithmetic raster function.

Syntax

Arithmetic(raster1, raster2, {operation_type}, {extent_type}, {cellsize_type})

Parameter Explanation Data Type

raster1

The first input raster. This can be a scalar raster where all pixels have the same value.

Raster

raster2

The second input raster. This can be a scalar raster where all pixels have the same value.

Raster

operation_type

The arithmetic operation to apply between the two input rasters.

  • Divide—Outputs the divisible result between the corresponding pixel values for each raster.

  • Minus—Outputs the difference between the corresponding pixel values for each raster. This operation can be used to calculate change detection.

  • Mode—Outputs the pixel value of all overlapping pixels that occurs the most. For example, if there are six bands in a raster, there will be six overlapping pixels. For the values 4, 5, 6, 4, 7, 9, the mode value is 4.

  • Multiply—Outputs the product of the corresponding pixel values for each raster. This operation can be used to perform some cost functions.

  • Plus—Outputs the sum of all the corresponding pixel values for each raster.

  • Power—Outputs the product of the corresponding pixel values raised to the power of the input raster or scalar.

The default value is Plus.

String

extent_type

The method to use to compute the extent of the output when the input rasters have different extents.

  • FirstOf—The output extent is defined using the extent of the first input raster.

  • LastOf—The output extent is defined using the extent of the last input raster.

  • IntersectionOf—The output extent is defined as the intersecting area of the input rasters.

  • UnionOf—The output extent is defined as the total extent of the input rasters.

The default value is FirstOf.

String

cellsize_type

The method to use to compute the cell size of the output when the input rasters have different cell sizes.

  • FirstOf—The output cell size is defined using the cell size of the first input raster.

  • LastOf—The output cell size is defined using the cell size of the last input raster.

  • MaxOf—The output cell size is defined using the maximum cell size of the input rasters.

  • MeanOf—The output cell size is defined using the mean of both input rasters.

  • MinOf—The output cell size is defined using the minimum cell size of the input rasters.

The default value is FirstOf.

String

Return value

Data Type Explanation

Raster

The output raster with the arithmetic operation applied.

Code sample

Arithmetic example

Multiplies two rasters and uses the total extent of the inputs.

import arcpy

new_raster = arcpy.sa.Arithmetic("Raster1.tif","Raster2.tif", "Multiply", "UnionOf", "FirstOf")