Statistics

摘要

基于已定义的焦点邻域计算影像中各像元的统计数据。

说明

有关此函数使用方法和波段顺序的详细信息,请参阅统计数据栅格函数。

栅格对象所引用的栅格数据集是临时性的。 要将其设置为永久,可以调用栅格对象的 save 方法。

语法

Statistics (raster, kernel_columns, kernel_rows, stat_type, {fill_no_data_only})
参数说明数据类型
raster

要执行焦点统计的输入栅格。

Raster
kernel_columns

要在焦点邻域尺寸中使用的像素列数。

(默认值为 3)

Integer
kernel_rows

要在焦点邻域尺寸中使用的像素行数。

(默认值为 3)

Integer
stat_type

指定要计算的统计类型。

  • max 计算邻域内像素的最大值。
  • mean 计算邻域内像素的平均值。这是默认设置。
  • min 计算邻域内像素的最小值。
  • standarddeviation计算邻域内像素的标准差值。
  • median计算邻域内像素的中值。
  • majority 计算邻域内像素的众数(出现次数最多的值)。
  • minority 计算邻域内像元的少数(出现次数最少的值)。

(默认值为 None)

String
fill_no_data_only

指定是否相似分析中忽略 NoData 值。

  • True - 仅填充 NoData 像素。这是默认设置。
  • False - 不会填充 NoData 像素。

(默认值为 False)

Boolean
返回值
数据类型说明
Raster

输出栅格。

代码示例

统计数据示例

使用 5 x 5 邻域中的多数值填写 NoData 值,以获取分类数据。

from arcpy.sa import *
LandCover_filled = arcpy.sa.Statistics("LandCover.tif", 5, 5, "majority", True)
LandCover_filles.save("LandCover_majority_5_by_5.tif")
统计数据示例

使用平均值对 3 x 3 邻域中的高程栅格进行平滑处理。

import arcpy
from arcpy import env
from arcpy.sa import *

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

# Set local variables
inRaster = "elevation.tif"
kernel_columns=3
kernel_rows=3
stat_type="Mean"
fill_no_data_only = False

# for each pixel, calculate the average value of pixels within its neighborhood. the neighborhood size is 5x5
output = Statistics(imagePath1, kernel_columns, kernel_rows, stat_type, fill_no_data_only)
output.save("statistics_mean_5_by_5.tif")

相关主题