# NbrWeight (arcpy.sa)

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

## 讨论

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

• 核文件属于 ASCII 文本文件，可定义权重邻域的值和形状。

• 第一行指定了邻域的宽度和高度（表示为由空格分开的 x 轴方向上的像元数和 y 轴方向上的像元数）。

• 随后几行则指定了邻域中各个位置的权重值。按照与各像元在所在邻域中相同的配置输入这些像元值。正值、负值和小数值均可用作权重。各个值之间需要由空格分隔。

• 对于邻域中不用于计算的位置，核文件中的相应位置将用值 0 表示。

## 语法

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 窗口）

``````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（独立脚本）

``````# 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")
``````

5/10/2014