# NbrRectangle (arcpy.sa)

## 插图 FocalStatistics 函数的 NbrRectangle 邻域。 BlockStatistics 函数的 NbrRectangle 邻域。

## 讨论

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

## 语法

NbrRectangle ({width}, {height}, {units})
 参数 说明 数据类型 width The width of the rectangle neighborhood. If only the width is specified, the resulting neighborhood is a square. (默认值为 3) Double height The height of the rectangle neighborhood. If only the height is specified, the resulting neighborhood is a square. (默认值为 3) Double units Defines the units of the neighborhood. CELL —The unit of measurement is in cells. MAP —The units are in map coordinates. (默认值为 CELL) String

## 属性

 属性 说明 数据类型 width(读写) The width of the rectangle neighborhood. If only the width is specified, the height will default to the same as the width, resulting in a square neighborhood. Double height(读写) The height of the rectangle neighborhood. If only the height is specified, the width will default to the same as the height, resulting in a square neighborhood. Double units(读写) Defines the units of the neighborhood. String

## 代码实例

NbrRectangle 示例 1（Python 窗口）

``````import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outNbrRec = BlockStatistics("block", NbrRectangle(4, 5, "MAP"))
outNbrRec.save("C:/sapyexamples/output/blstatsnbrr2")
``````
NbrRectangle 示例 2（独立脚本）

``````# Name: NbrRectangle_Ex_02.py
# Description: Uses the NbrRectangle 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
width = 5
height = 6
myNbrRec = NbrRectangle(width, height, "MAP")

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

# Execute BlockStatistics
outBlkStat =  BlockStatistics(inRaster, myNbrRec, "MINIMUM", "DATA")

# Save the output
outBlkStat.save("C:/sapyexamples/output/blstat_rec3")
``````

5/10/2014