NbrRectangle
汇总
用于定义矩形邻域,将通过以地图单位或像元数指定高度和宽度来创建该邻域。


讨论
使用矩形邻域对象的工具包括: 块统计 、 焦点统计 、 点统计 、 点密度分析 和 地形位置指数 。
许可:
如果您拥有 Image Analyst 扩展模块许可,也可以使用该类,但仅限于 焦点统计 工具。
通过提供以像元或地图单元为单位的 width 和 height ,指定矩形邻域。
当在焦点工具中使用矩形时,邻域范围内待处理像元相对于邻域左上角的 x,y 位置可通过以下方程式来确定:
\(x \space = \space (邻域的宽度 \space + \space 1)/2 \space y \space = \space (邻域的高度 \space + \space 1)/2\)
如果输入像元数为偶数,则将使用截断来计算 x,y 坐标。
仅将中心在定义对象内的像元作为矩形邻域的一部分进行处理。
语法
NbrRectangle({width}, {height}, {units})
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
width (可选) |
The width of the rectangle neighborhood. If only the (默认值为 3) |
Double |
|
height (可选) |
The height of the rectangle neighborhood. If only the (默认值为 3) |
Double |
|
units (可选) |
Defines the units of the neighborhood.
(默认值为 CELL) |
String |
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
width (读取和写入) |
矩形邻域的宽度。 如果仅指定 |
Double |
|
height (读取和写入) |
矩形邻域的高度。 如果仅指定 |
Double |
|
units (读取和写入) |
定义邻域单位。
|
String |
代码示例
演示如何创建 NbrRectangle 类以及如何在 Python 窗口的 BlockStatistics 工具中使用该类。
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 类执行 BlockStatistics 工具。
# Name: NbrRectangle_Ex_02.py
# Description: Uses the NbrRectangle object to run 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")
# Run BlockStatistics
outBlkStat = BlockStatistics(inRaster, myNbrRec, "MINIMUM", "DATA")
# Save the output
outBlkStat.save("C:/sapyexamples/output/blstat_rec3")