// (整除) (arcpy.sa)

摘要

将两个栅格的值逐像元地整除。

插图

Divide illustration
OutRas = Raster("InRas1") // Raster("InRas2")

讨论

使用具有栅格输入的运算符时,结果将为栅格。但是,如果所有输入为数字,那么结果也是数字。

当表达式中使用多个运算符时,其不一定按照从左到右的顺序执行。具有最高优先值的运算符将首先执行。有关运算符优先级的详细信息,请参阅运算符优先级表。您可使用括号来控制执行顺序。

此运算符的运算结果与输入的顺序有关。

当一个数除以零时,输出结果为 NoData。

如果两个输入均为整数,则输出为整数值。例如,如果 5 除以 2,则输出为 2(舍去余数)。

如果其中一个输入为浮点型,则输出的商将为浮点型。例如,如果 5.3 除以 2,则输出为 2.0(舍去余数 0.65)。

执行“整除”运算的另一个方法为 a //= b,这是 a = a // b 的另一种写法。

语法

in_raster_or_constant1 // in_raster_or_constant2
操作数说明数据类型
in_raster_or_constant1

The input whose values will be divided by the second input.

If the first input is a raster and the second is a scalar, an output raster is created with each input raster value being divided by the scalar value.

Raster Layer | Constant
in_raster_or_constant2

The input whose values the first input are to be divided by.

If the first input is a scalar and the second is a raster, an output raster is created with each input raster value being divided into the scalar value.

Raster Layer | Constant

返回值

名称说明数据类型
out_raster

输出栅格对象。

The cell values are the quotient of the first input raster (dividend) divided by the second input (divisor).

Raster

代码实例

// (Integer Division) example 1 (Python window)

This sample divides the values of the first input raster by the second.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outDivide = Raster("degs") // Raster("negs")
outDivide.save("C:/sapyexamples/output/outdivide")
// (Integer Division) example 2 (stand-alone script)

This sample divides the values of the first input raster by the second.

# Name: Op_IntegerDivide_Ex_02.py
# Description: Divides 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
inRaster01 = Raster("elevation")
inRaster02 = Raster("landuse")

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

# Execute Integer Divide
outDivide = inRaster01 // inRaster02

# Save the output 
outDivide.save("C:/sapyexamples/output/outdivide2")

环境

相关主题

9/15/2013