Skip to main content

NbrRectangle

汇总

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

FocalStatistics 函数的 NbrRectangle 邻域

FocalStatistics 函数的 NbrRectangle 邻域示例。

BlockStatistics 函数的 NbrRectangle 邻域

BlockStatistics 函数的 NbrRectangle 邻域示例(宽度 = 6 像元,高度 = 4 像元)。

讨论

使用矩形邻域对象的工具包括: 块统计焦点统计点统计点密度分析地形位置指数

许可:

如果您拥有 Image Analyst 扩展模块许可,也可以使用该类,但仅限于 焦点统计 工具。

通过提供以像元或地图单元为单位的 widthheight ,指定矩形邻域。

当在焦点工具中使用矩形时,邻域范围内待处理像元相对于邻域左上角的 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 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

(读取和写入)

矩形邻域的宽度。

如果仅指定 width ,则 height 将默认与 width 相同,由此生成一个方形邻域。

Double

height

(读取和写入)

矩形邻域的高度。

如果仅指定 height ,则 width 将默认与 height 相同,由此生成一个方形邻域。

Double

units

(读取和写入)

定义邻域单位。

  • CELL—单位为像元的数量。

  • MAP—单位位于地图坐标中。

String

代码示例

NbrRectangle 示例 1(Python 窗口)

演示如何创建 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 示例 2(独立脚本)

使用 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")