The Raster Cell Iterator (RCI) allows you to visit each cell location in a Raster object. The iterator makes it easy to inspect cell values at each location and neighboring locations. While iterating over a raster, you can read as well as write cell values. RCI is available through the Spatial Analyst module, an extension of the ArcPy Python site package. Iterable access to raster cells enables you to write custom raster analysis scripts and combine them with the existing suite of Spatial Analysis geoprocessing tools.
A simple example of how to use RCI is shown below.
from arcpy.sa import * myRas = Raster("myras") for i, j in myRas: print(i, j, myRas[i, j])
The code example shown here creates a Raster object called myRas, created from an existing raster dataset myras. A raster cell iterator is defined on the Raster object, which enumerates row and column indices of raster cells in a loop. Within the iterator, the row index i, column index j, and cell value myRas[i,j] are queried at each cell location.