Skip To Content

Foreach

Available with Image Analyst license.

Summary

Creates a raster object by applying a raster function or a customized function template to every slice in the input multidimensional raster.

Discussion

Use the Foreach function to apply a raster function to every slice in a multidimensional raster dataset. To apply a raster function to a single slice, use the Subset function before using Foreach.

This function creates a raster object that contains the variables and dimensions of the input multidimensional raster, processed using a raster function. The referenced raster dataset for the raster object is temporary. To make it permanent, you can call the raster object's save method.

Syntax

Foreach (in_raster, raster_function, {raster_function_arguments})
ParameterExplanationData Type
in_raster

The input multidimensional raster dataset.

Raster
raster_function

The name of a raster function or the path to a custom raster function (.rft.xml file) to apply to every slice in the input multidimensional raster.

String
raster_function_arguments

The parameters and values associated with the raster function or function chain. If not specified, default values will be used.

For example, the Tasseled Cap function does not require any arguments; the input is a single raster, so there is no need to specify arguments.

The Arithmetic function, however, requires 5 input parameters: Raster, Raster2, Operation, Cellsize Type and Extent Type. To use Arithmetic with the Apply function, Raster and Raster2 are defined in the in_raster parameter, and the remaining parameters have default values, so if nothing is specified for those parameters, the default values will be used.

For information about the function arguments for each raster function, see Raster function objects.

Dictionary
Return Value
Data TypeExplanation
Raster

The output multidimensional raster.

Code sample

Foreach example

Calculate NDVI for each slice in a time series of Landsat 7 scenes.

Missing source code file