Nibble (Spatial Analyst)

Available with Spatial Analyst license.

Summary

Replaces cells of a raster corresponding to a mask with the value of the nearest neighbor.

Learn more about how Nibble works

Illustration

Nibble tool illustration
OutRas = Nibble(InRas1, Mask_Ras)

Usage

  • You can use the Nibble tool to select areas of a raster and assign them the value of their nearest neighbor. The tool can be used to replace a few individual cells with the values immediately nearby. With larger mask areas, larger swaths of cells can be replaced.

    A common application is for editing areas of a raster where the data is known to be erroneous.

  • Cells that are NoData in the input mask raster define which cells will be replaced. Any locations in the input raster that are not within the mask area will not be replaced, and the output value for them will be the same as the input value.

    NoData cells in the input raster that are not within the mask are not replaced. The cells will remain NoData regardless of the settings of the two NoData parameters.

  • This tool supports parallel processing. If your computer has multiple processors or processors with multiple cores, better performance may be achieved, particularly on larger datasets. The Parallel processing with Spatial Analyst help topic has more details on this capability and how to configure it.

    When using parallel processing, temporary data will be written to manage the data chunks being processed. The default temp folder location will be on your local C drive. You can control the location of this folder by setting up a system environment variable named TempFolders and specifying the path to a folder to use (for example, E:\RasterCache). If you have admin privileges on your machine, you can also use a registry key (for example, [HKEY_CURRENT_USER\SOFTWARE\ESRI\ArcGISPro\Raster]).

    By default, this tool will use 50 percent of the available cores. If the input data is smaller than 5,000 by 5,000 cells in size, fewer cores may be used. You can control the number of cores the tool uses with the Parallel processing factor environment.

  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Parameters

LabelExplanationData Type
Input raster

The input raster with the masked locations that will be replaced by the value of their nearest neighbor.

The input raster can be either integer or floating point type.

Raster Layer
Input raster mask

The raster that identifies the locations in the input raster that will be replaced.

Cells with a value of NoData are considered to be within the masked area. In the output raster, these locations will be replaced by the value of their nearest neighbor in the Input raster value.

The mask raster can be either integer or floating point type.

Raster Layer
Use NoData values if they are the nearest neighbor
(Optional)

Specifies whether NoData cells in the input raster can replace cells in the masked areas if they are the nearest neighbor.

  • Checked—Both NoData and data values can replace cells in the masked area. This means that NoData values in the input raster can replace areas defined in the mask if they are the nearest neighbor. This is the default.
  • Unchecked—Only data values can replace cells in the masked area. NoData values in the input raster cannot replace areas defined in the mask raster even if they are the nearest neighbor.
Boolean
Nibble NoData cells
(Optional)

Specifies whether NoData cells in the input raster that are within the masked area will be preserved or replaced.

  • Unchecked—Any NoData cells in the input raster that are within the masked area will be preserved (remain as NoData) in the output. This is the default.
  • Checked—NoData cells in the input raster that are within the masked area can be replaced with the value of the nearest neighbor that is outside the masked area.
Boolean
Input zone raster
(Optional)

The input zone raster. For each zone, input cells that are within the mask will be replaced only by the nearest cell values within that same zone.

A zone is all the cells in a raster that have the same value, whether or not they are contiguous. The input zone layer defines the shape, values, and locations of the zones. The zone raster can be either integer or floating point type.

Raster Layer

Return Value

LabelExplanationData Type
Output raster

The output raster with the replaced cells.

The identified input cells will be replaced with the values of their nearest neighbor.

If the in_raster value is integer, the output raster will be integer. If it is floating point, the output will be floating point.

Raster

Nibble(in_raster, in_mask_raster, {nibble_values}, {nibble_nodata}, {in_zone_raster})
NameExplanationData Type
in_raster

The input raster with the masked locations that will be replaced by the value of their nearest neighbor.

The input raster can be either integer or floating point type.

Raster Layer
in_mask_raster

The raster that identifies the locations in the input raster that will be replaced.

Cells with a value of NoData are considered to be within the masked area. In the output raster, these locations will be replaced by the value of their nearest neighbor in the in_raster value.

The mask raster can be either integer or floating point type.

Raster Layer
nibble_values
(Optional)

Specifies whether NoData cells in the input raster can replace cells in the masked areas if they are the nearest neighbor.

  • ALL_VALUESBoth NoData and data values can replace cells in the masked area. This means that NoData values in the input raster can replace areas defined in the mask if they are the nearest neighbor. This is the default.
  • DATA_ONLYOnly data values can replace cells in the masked area. NoData values in the input raster cannot replace areas defined in the mask raster even if they are the nearest neighbor.
Boolean
nibble_nodata
(Optional)

Specifies whether NoData cells in the input raster that are within the masked area will be preserved or replaced.

  • PRESERVE_NODATA Any NoData cells in the input raster that are within the masked area will be preserved (remain as NoData) in the output. This is the default.
  • PROCESS_NODATANoData cells in the input raster that are within the masked area can be replaced with the value of the nearest neighbor that is outside the masked area.
Boolean
in_zone_raster
(Optional)

The input zone raster. For each zone, input cells that are within the mask will be replaced only by the nearest cell values within that same zone.

A zone is all the cells in a raster that have the same value, whether or not they are contiguous. The input zone layer defines the shape, values, and locations of the zones. The zone raster can be either integer or floating point type.

Raster Layer

Return Value

NameExplanationData Type
out_raster

The output raster with the replaced cells.

The identified input cells will be replaced with the values of their nearest neighbor.

If the in_raster value is integer, the output raster will be integer. If it is floating point, the output will be floating point.

Raster

Code sample

Nibble example 1 (Python window)

This example replaces cells identified by the mask input with values determined by the nearest neighbors of the input raster.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
nibbleOut = Nibble("land", "snow", "DATA_ONLY")
nibbleOut.save("C:/sapyexamples/output/nibbleout")
Nibble example 2 (stand-alone script)

This example replaces cells identified by the mask input with values determined by the nearest neighbors of the input raster.

# Name: Nibble_Ex_02.py
# Description: Replaces cells of a raster corresponding to a mask 
#              with the values of the nearest neighbors.
# 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 = "land"
inMask = "snow"

# Execute Nibble
nibbleOut = Nibble(inRaster, inMask, "ALL_VALUES")

# Save the output 
nibbleOut.save("C:/sapyexamples/output/outnibble")

Licensing information

  • Basic: Requires Spatial Analyst
  • Standard: Requires Spatial Analyst
  • Advanced: Requires Spatial Analyst

Related topics