+ (Addition) (arcpy.sa)

Resumen

Adds (sums) the values of two rasters on a cell-by-cell basis.

Ilustración

Plus illustration
OutRas = Raster("InRas1") + Raster("InRas2")

Debate

Cuando se utiliza un operador con una entrada ráster, el resultado será un ráster. Sin embargo, si todas las entradas son números, entonces el resultado es un número.

Cuando se utilizan varios operadores en una expresión, no necesariamente se ejecutan en orden de izquierda a derecha. El operador con el valor de jerarquía más alta se ejecutará primero. Para obtener más información sobre la jerarquía del operador, consulte la tabla jerarquía del operador. Puede utilizar paréntesis para controlar el orden de ejecución.

El orden de entrada no es importante para este operador.

Si los valores de entrada son enteros, los valores de salida serán enteros; de lo contrario, las salidas serán puntos flotantes.

Another way to perform the addition operation is a += b, which is an alternative way to write a = a + b.

Sintaxis

in_raster_or_constant1 + in_raster_or_constant2
OperandoExplicaciónTipo de datos
in_raster_or_constant1

The input to which values will be added.

If one of the input is a raster and the other is a scalar, an output raster is created with the scalar value being added to each cell in the input raster.

Raster Layer | Constant
in_raster_or_constant2

The input whose values will be added to the first input.

If one of the inputs is a raster and the other is a scalar, an output raster is created with the scalar value being added to each cell in the input raster.

Raster Layer | Constant

Valor de retorno

NombreExplicaciónTipo de datos
out_raster

El objeto ráster de salida.

The cell values are the sum of the first input added to the second.

Raster

Ejemplo de código

+ (Addition) example 1 (Python window)

This sample adds two input rasters.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outPlus = Raster("degs") + Raster("negs")
outPlus.save("C:/sapyexamples/output/outplus.img")
+ (Addition) example 2 (stand-alone script)

This sample adds two input rasters.

# Name: Op_Plus_Ex_02.py
# Description: Adds the values of two rasters on a cell-by-cell basis.
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inRaster1 = Raster("cost")
inRaster2 = Raster("degs")

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute Plus
outPlus = inRaster1 + inRaster2

# Save the output 
outPlus.save("C:/sapyexamples/output/outplus")

Entornos

Temas relacionados

9/12/2013