NbrWeight (arcpy.sa)

摘要

定义使用核文件创建的权重邻域,该核文件指定用于乘以邻域范围内像元的值。

插图

NbrWeight 邻域 FocalStatistics 图像
FocalStatistics 函数的 NbrWeight 邻域。
NbrWeight 邻域 BlockStatistics 图像
BlockStatistics 工具的 NbrWeight 邻域。

讨论

使用邻域权重对象的工具包括:块统计焦点统计

使用核文件指定权重邻域。核文件用来标识应包含在邻域范围内的像元位置以及用于乘以输入栅格中像元值的权重。

对于焦点统计工具,可通过以下方程确定邻域范围内待处理像元相对于邻域左上角的 x,y 位置:

 x = (width + 1)/2
 y = (height + 1)/2

如果输入像元数为偶数,则可通过截断操作来计算 x 和 y 坐标。

核文件:

语法

NbrWeight (inKernelFile)
参数说明数据类型
inKernelFile

The inKernelFile is an ASCII text file that defines the shape of the neighborhood and the weight of each cell in that neighborhood. A value of 0 for a cell position indicates that the cell is not a member of the neighborhood, and a number at a corresponding cell's position indicates that the cell value be included as a member of the neighborhood. The nonzero value will also serve as the weight to multiply the corresponding cell value.

File

属性

属性说明数据类型
inKernelFile
(读写)

The inKernelFile is an ASCII text file that defines the shape of the neighborhood and the weight of each cell in that neighborhood. A value of 0 for a cell position indicates that the cell is not a member of the neighborhood, and a number at a corresponding cell's position indicates that the cell value be included as a member of the neighborhood. The nonzero value will also serve as the weight to multiply the corresponding cell value.

String

代码实例

NbrWeight 示例 1(Python 窗口)

演示如何创建 NbrWeight 类以及如何在 Python 窗口的 BlockStatistics 工具中使用该类。

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outNbrWF = BlockStatistics("block", NbrWeight("weight.txt"))
outNbrWF.save("C:/sapyexamples/output/blstatsnbrwf2")
NbrWeight 示例 2(独立脚本)

使用 NbrWeight 类执行 BlockStatistics 工具。

# Name: NbrWeight_Ex_02.py
# Description: Uses the NbrWeight object to execute BlockStatistics tool.
# 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
inRaster = "block"

# Create the Neighborhood Object
inWeightFile = "C:/data/weight.txt"
myNbrWeight = NbrWeight(inWeightFile)

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

# Execute BlockStatistics
outBlStats =  BlockStatistics(inRaster, myNbrWeight, "MINIMUM", "DATA")

# Save the output 
outBlStats.save("C:/sapyexamples/output/blstat_wght3")

相关主题

9/15/2013