Region Group (Spatial Analyst)

Summary

For each cell in the output, the identity of the connected region to which that cell belongs is recorded. A unique number is assigned to each region.

Learn more about creating individual zones with Region Group

Illustration

Region Group illustration
OutRas = RegionGroup(InRas1)

Usage

Syntax

RegionGroup (in_raster, {number_neighbors}, {zone_connectivity}, {add_link}, {excluded_value})
ParameterExplanationData Type
in_raster

The input raster whose unique connected regions will be identified.

It must be of integer type.

Raster Layer
number_neighbors
(Optional)

The number of neighboring cells to use in evaluating connectivity between cells.

  • FOUR Defines connectivity between cells of the same value only if the cells are directly to the left, right, above, or below each of the four nearest neighbors. If two cells with the same value are diagonal from one another, they are not considered connected.
  • EIGHT Defines connectivity between cells of the same value if they are within the immediate eight-cell neighborhood (eight nearest neighbors) of each other. This includes to the right, left, above, or diagonal to each other.
String
zone_connectivity
(Optional)

Defines which cell values should be considered when testing for connectivity.

  • WITHIN Tests connectivity between input values that are the same within the same zone.The only cells that can be grouped are cells from the same zone (value) that meet the spatial requirements of connectivity specified by the FOUR and EIGHT keywords.
  • CROSS Tests connectivity by the spatial requirements specified by the keywords FOUR or EIGHT between cells with any values, except for the value identified to be excluded.When CROSS is used, a value for the {excluded_value} argument must be input.
String
add_link
(Optional)

Specifies whether a link field is added to the table of the output.

  • ADD_LINK An ADD_LINK item will be added to the table of the output raster. This item stores the original values for each newly created zone, from disconnected regions, from the input raster before they are regrouped. This is the default.
  • NO_LINK The attribute table for the output raster will only contain the Value and Count items.
Boolean
excluded_value
(Optional)

Identifies a value such that if a cell location contains the value, no spatial connectivity will be evaluated regardless how the number of neighbors is specified (FOUR or EIGHT).

Cells with the excluded value will be treated as NoData and are eliminated from calculations. Cell locations that contain the excluded value will receive 0 on the output raster.

The excluded value is similar to the concept of a background value, or setting a mask in the environment for a single run of the tool. A value must be specified for this parameter if the CROSS keyword is specified.

Long

Return Value

NameExplanationData Type
out_raster

The output region group raster.

The output raster is always of integer type.

Raster

Code Sample

RegionGroup example 1 (Python window)

This example assigns a unique number to each region of the input raster using eight-way connectivity.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outRgnGrp = RegionGroup("land", "EIGHT", "", "", 5)
outRgnGrp.save("c:/sapyexamples/output/reggrp_ex5")
RegionGroup example 2 (stand-alone script)

This example assigns a unique number to each region of the input raster using eight-way connectivity with an excluded value.

# Name: RegionGroup_Ex_02.py
# Description: Records, for each cell in the output, the
#              identity of the connected region to which 
#              it belongs within the Analysis window. A 
#              unique number is assigned to each region.
# Requirements: Spatial Analyst Extension
# Author: ESRI

# 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"
valToIgnore = 5

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

# Execute RegionGroup
outRegionGrp = RegionGroup(inRaster, "EIGHT", "CROSS", 
                           "NO_LINK", valToIgnore)

# Save the output 
outRegionGrp.save("C:/sapyexamples/output/reggrpout")

Environments

Related Topics

Licensing Information

ArcView: Requires Spatial Analyst
ArcEditor: Requires Spatial Analyst
ArcInfo: Requires Spatial Analyst

6/29/2011