NbrRectangle (arcpy.sa)

摘要

定义通过指定以地图单位或像元数为单位的高度和宽度而创建的矩形邻域。

插图

NbrRectangle 邻域 FocalStatistics 图像
FocalStatistics 函数的 NbrRectangle 邻域。
NbrRectangle 邻域 BlockStatistics 图像
BlockStatistics 函数的 NbrRectangle 邻域。

讨论

使用邻域矩形对象的工具包括:块统计焦点统计点统计点密度

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

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

 x = (width of the neighborhood + 1)/2
 y = (height of the neighborhood + 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.

  • CELLThe unit of measurement is in cells.
  • MAPThe 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 窗口)

演示如何创建 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 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