Gradient

摘要

计算沿 x、y、x,y 或给定维度的梯度。

说明

Gradient 函数适用于单波段输入。 如果输入为多波段,则会使用第一个波段。 使用 ExtractBand 函数指定需要的波段。

对于包含多个变量的多维输入,将会处理所有变量。 如果变量不包含指定的 gradient_dimension 参数,则其会被忽略。 使用多维过滤器函数选择所需变量。

多维过滤器函数也可以用于定义要应用函数的维度范围。

下表列出了多种梯度计算的等式。

梯度类型等式

梯度 X

(右侧像素 - 当前像素)/分母单位

梯度 Y

(下方像素 - 当前像素)/分母单位

维度的梯度

(下一个剖切片 - 当前剖切片)/分母单位

语法

Gradient (raster, {gradient_dimension}, {denominator_unit})
参数说明数据类型
raster
[raster,...]

The input raster or list of rasters.

Raster
gradient_dimension

The available dimensions for which the gradient will be calculated.

For nonmultidimensional input, available dimension options are X, Y, and XY.

For multidimensional input, available dimension options are X, Y, XY, and all dimensions available in the data, including time (StdTime). If there are two or more dimensions, the gradient will be calculated on the gradient dimension for all slices in the available dimensions.

The XY option outputs a 2-band raster in which band 1 represents the gradient along the x-dimension, and band 2 represents the gradient along the y-dimension.

(默认值为 X)

String
denominator_unit

The unit of the gradient denominator. The unit depends on the gradient_dimension argument value.

The following options are available for X, Y, and XY:

  • DEFAULT—The output will be the difference between adjacent cells. This is the default.
  • CELLSIZE—The output will be the difference between adjacent cells divided by the cell size of the input. The output unit will be the same as the unit of the x,y coordinates of the input. If the data is in a geographic coordinate system, it will be converted to meters.

The following options are available for StdTime:

  • DEFAULT—The output will be the difference between adjacent slices. This is the default.
  • PER_HOUR—The output will be the difference between adjacent slices divided by the difference between the time values and converted to the per-hour rate.
  • PER_DAY—The output will be the difference between adjacent slices divided by the difference between their time values and converted to the per-day rate.
  • PER_MONTH—The output will be the difference between adjacent slices divided by the difference between their time values and converted to the per-month rate.
  • PER_YEAR—The output will be the difference between adjacent slices divided by the difference between their time values and converted to the per-year rate.
  • PER_DECADE—The output will be the difference between adjacent slices divided by the difference between their time values and converted to the per-decade rate.

The following options are available for dimensions other than time dimensions:

  • DEFAULT—The output will be the difference between adjacent slices. This is the default.
  • DIMENSION_INTERVAL—The output will be the difference between adjacent slices divided by the difference between their dimension values.

(默认值为 DEFAULT)

String
返回值
数据类型说明
Raster

输出栅格。

代码示例

Gradient 示例 1

计算 Landsat 图像在 x 和 y 维度上的梯度。

# Import system modules
import arcpy
from arcpy.ia import *
arcpy.ia.Gradient (raster, gradient_dimension, denominator_unit)
# Check out the ArcGIS Image Analyst extension license
arcpy.CheckOutExtension("ImageAnalyst")
# Set local variables
input_raster = in_multidimensional_raster = "C:/data/landsat.crf"
gradient_dimension = “XY”
denominator_unit = “Cellsize”
# Apply Gradient function
gradient_raster = arcpy.ia.Gradient (raster, gradient_dimension, denominator_unit)
# Save the output
gradient _raster.save("C:/output/landsat_xy_gradient.crf")
Gradient 示例 2

该示例计算了 NDVI 时间序列在 StdTime 维度上的梯度。

# Import system modules
import arcpy
from arcpy.ia import *
arcpy.ia.Gradient (raster, gradient_dimension, denominator_unit)
# Check out the ArcGIS Image Analyst extension license
arcpy.CheckOutExtension("ImageAnalyst")
# Set local variables
input_raster = in_multidimensional_raster = "C:/data/ndvi_time_series.crf"
gradient_dimension = “StdTime”
denominator_unit = “Per Year”
# Apply Gradient function
gradient_raster = arcpy.ia.Gradient (raster, gradient_dimension, denominator_unit)
# Save the output
gradient _raster.save("C:/output/ndvi_stdtime_gradient.crf")