NbrWeight (arcpy.sa)

Resumen

Defines a weight neighborhood which is created using a kernel file specifying the values to multiply the cell by that are within the neighborhood.

Ilustración

NbrWeight neighborhood FocalStatistics image
NbrWeight neighborhood for the FocalStatistics function.
NbrWeight neighborhood BlockStatistics image
NbrWeight neighborhood for the BlockStatistics tool.

Debate

Tools that use neighborhood weight object: Block Statistics and Focal Statistics.

The weight neighborhood is specified using a kernel file. The kernel file identifies which cell positions should be included within the neighborhood and the weights that will be used to multiply the cell values by on the input raster.

For focal tools the x,y position for the processing cell within the neighborhood, with respect to the upper-left corner of the neighborhood, is determined by the following equations:

 x = (width + 1)/2
 y = (height + 1)/2

If the input number of cells is even, the x and y coordinates are computed using truncation.

The kernel file:

Sintaxis

NbrWeight (inKernelFile)
ParámetroExplicaciónTipo de datos
inKernelFile

The inKernelFile is an ASCII text file that defines the shape of the neighborhood and the weight of each cell in that neighborhood. A value of 0 for a cell position indicates that the cell is not a member of the neighborhood, and a number at a corresponding cell's position indicates that the cell value be included as a member of the neighborhood. The nonzero value will also serve as the weight to multiply the corresponding cell value.

File

Propiedades

PropiedadExplicaciónTipo de datos
inKernelFile
(Lectura y escritura)

The inKernelFile is an ASCII text file that defines the shape of the neighborhood and the weight of each cell in that neighborhood. A value of 0 for a cell position indicates that the cell is not a member of the neighborhood, and a number at a corresponding cell's position indicates that the cell value be included as a member of the neighborhood. The nonzero value will also serve as the weight to multiply the corresponding cell value.

String

Ejemplo de código

NbrWeight example 1 (Python window)

Demonstrates how to create a NbrWeight class and use it in the BlockStatistics tool within the Python window.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outNbrWF = BlockStatistics("block", NbrWeight("weight.txt"))
outNbrWF.save("C:/sapyexamples/output/blstatsnbrwf2")
NbrWeight example 2 (stand-alone script)

Implements the BlockStatistics tool using the NbrWeight class.

# Name: NbrWeight_Ex_02.py
# Description: Uses the NbrWeight 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
inWeightFile = "C:/data/weight.txt"
myNbrWeight = NbrWeight(inWeightFile)

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

# Execute BlockStatistics
outBlStats =  BlockStatistics(inRaster, myNbrWeight, "MINIMUM", "DATA")

# Save the output 
outBlStats.save("C:/sapyexamples/output/blstat_wght3")

Temas relacionados

9/12/2013