NbrIrregular (arcpy.sa)
摘要
定义由核文件创建的不规则邻域。
插图
讨论
核文件指定应包含在邻域范围内的像元位置。
对于焦点统计工具,可通过以下方程确定邻域范围内待处理像元相对于邻域左上角的 x,y 位置:
x = (width + 1)/2 y = (height + 1)/2
如果输入像元数为偶数,则可通过截断操作来计算 x 和 y 坐标。
核文件:
核文件属于 ASCII 文本文件,可定义不规则邻域的值和形状。
第一行指定了邻域的宽度和高度(表示为由空格分开的 x 轴方向上的像元数和 y 轴方向上的像元数)。
随后几行则指定了邻域中各个位置的值。按照与各像元在所在邻域中相同的配置输入这些像元值。各个值之间需要由空格分隔。
核文件中的值非 0 即 1。且会将任何非 0 值视为 1。
某像元位置的值为 0(非空)表示该像元不属于该邻域从而无法用于邻域处理。而值为 1 则表示该值对应的像元(和像元值)属于该邻域。
语法
参数 | 说明 | 数据类型 |
inKernelFile |
The irregular inKernelFile is an ASCII text file that defines the shape of an irregular neighborhood. A value of 0 for a cell position indicates that the cell is not a member of the neighborhood, and a nonzero number at a corresponding cell's position indicates that the cell value be included as a member of the neighborhood. | File |
属性
属性 | 说明 | 数据类型 |
inKernelFile (读写) |
The irregular inKernelFile is an ASCII text file that defines the shape of an irregular neighborhood. A value of 0 for a cell position indicates that the cell is not a member of the neighborhood, and a nonzero number at a corresponding cell's position indicates that the cell value be included as a member of the neighborhood. | String |
代码实例
演示如何创建 NbrIrregular 类以及如何在 Python 窗口的 BlockStatistics 工具中使用该类。
import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outNbrKF = BlockStatistics("block", NbrIrregular("irreg.txt"))
outNbrKF.save("C:/sapyexamples/output/blstatsnbri2")
使用 NbrIrregular 类执行 BlockStatistics 工具。
# Name: NbrIrregular_Ex_02.py
# Description: Uses the NbrIrregular 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
inKernelFile = "C:/data/irreg.txt"
myNbrIrreg = NbrIrregular(inKernelFile)
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute BlockStatistics
outBlkStat = BlockStatistics(inRaster, myNbrIrreg, "MINIMUM", "DATA")
# Save the output
outBlkStat.save("C:/sapyexamples/output/blstat_irr3")