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
Usage
-
The first region scanned receives the value one, the second two, and so forth, until all regions are assigned a value. The scan moves from left to right, top to bottom. The values assigned to the output zones are based on when they are encountered in the scanning process.
-
By default, the Add Link option is True. This will create an item called LINK in the attribute table of the output raster, which retains the original value for each cell from the input raster.
-
The LINK field allows you to trace the parentage of each of the newly created regions for queries or analysis.
For example, the attribute table for the output raster shown in the illustration above is:
-
Setting the Add Link option to False will significantly speed up processing. This is helpful when the original value of each region is no longer needed.
-
If a mask has been set in the evironment, those cells that have been masked will receive NoData on the output raster. With a mask, the spatial configuration and the number of regions may be altered on the output raster. If a region was continuous and the imposition of a mask breaks the continuity, the region will be divided into two regions with different values or grouping identifiers on the output raster.
The mask cannot only create additional regions by dividing a region into two or more separate regions, it can also reduce the number of regions on the output. If a mask totally covers or eliminates a potential region of connected cells, these cells will not be considered as a new zone on the output; they will receive NoData values.
-
Region Group is especially useful when the analysis is on regions and not on zones. Since the input zone value is maintained, the original zonal class can also be used in the analysis.
-
Cell locations that contain the excluded value receive zero on the output so that these zones are not confused with existing NoData cell locations. Since the Region Group begins numbering with the value 1, the cells that are excluded from the regroup are considered background. These background cells can be reclassed or manipulated as any other value. The locations containing excluded values can easily be converted to NoData using the Con tool.
Syntax
Parameter | Explanation | Data 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.
| String |
zone_connectivity (Optional) |
Defines which cell values should be considered when testing for connectivity.
| String |
add_link (Optional) |
Specifies whether a link field is added to the table of the output.
| 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
Name | Explanation | Data Type |
out_raster |
The output region group raster. The output raster is always of integer type. | Raster |
Code Sample
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")
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
# 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")