How to create an Arithmetic function dataset


Creating an Arithmetic function dataset

To create an Arithmetic function dataset, follow these steps:
  1. Create the Function Arguments object.
  2. Set the parameters for the function.
    1. Specify the operation.
    2. Specify the operands. The operands can be raster's or scalars.
    3. Specify how to calculate the extent for the output raster.
    4. Specify how to set the pixel size for the output raster.
  3. Create a Raster Function object.
  4. Create a Function Raster Dataset object.
  5. Create a name object for the function raster dataset.
  6. Specify the output file name for the new dataset.
  7. Initialize the new function raster dataset with the raster function and its arguments.
The following code example shows how to create an Arithmetic function raster dataset by applying the Arithmetic raster function to an image:
[C#]
// Create the Function Arguments object.
IArithmeticFunctionArguments rasterFunctionArguments = (IArithmeticFunctionArguments)
    new ArithmeticFunctionArguments();

// Set the parameters for the function:
// Specify the operation as addition (esriRasterPlus).
rasterFunctionArguments.Operation = esriRasterArithmeticOperation.esriRasterPlus;

// Specify the operands.
// The input data can be of type IRasterDataset, IRasterBand, or IRaster, 
// or one or more scalar values.
rasterFunctionArguments.Raster = inputDataA;
rasterFunctionArguments.Raster2 = inputDataB;

// Set which raster to get the output cellsize from.
((IArithmeticFunctionArguments2)rasterFunctionArguments).CellsizeType =
    esriCellsizeType.esriCellsizeMinOf;
// Set which raster to get the output extents from.
((IArithmeticFunctionArguments2)rasterFunctionArguments).ExtentType =
    esriExtentType.esriExtentFirstOf;

// Create the Raster Function object.
IRasterFunction rasterFunction = new ArithmeticFunction();
// Create the Function Raster Dataset object.
IFunctionRasterDataset functionRasterDataset = new FunctionRasterDataset();
// Create a name object for the Function Raster Dataset.
IFunctionRasterDatasetName functionRasterDatasetName = (IFunctionRasterDatasetName)
    new FunctionRasterDatasetName();
// Specify the output file name for the new dataset (including the .afr extension at the end).
functionRasterDatasetName.FullName = @"c:\temp\ArithmaticFunction.afr";
functionRasterDataset.FullName = (IName)functionRasterDatasetName;
// Initialize the new Function Raster Dataset with the Raster Function and its arguments.
functionRasterDataset.Init(rasterFunction, rasterFunctionArguments);
[VB.NET]
' Create the Function Arguments object.
Dim rasterFunctionArguments As IArithmeticFunctionArguments
rasterFunctionArguments = New ArithmeticFunctionArguments()

' Set the parameters for the function:
' Specify the operation as addition (esriRasterPlus).
rasterFunctionArguments.Operation = esriRasterArithmeticOperation.esriRasterPlus

' Specify the operands.
' The input data can be of type IRasterDataset, IRasterBand, or IRaster,
' or one or more scalar values.
rasterFunctionArguments.Raster = inputDataA
rasterFunctionArguments.Raster2 = inputDataB

' Set which raster to get the output cellsize from.
DirectCast(rasterFunctionArguments, IArithmeticFunctionArguments2).CellsizeType = esriCellsizeType.esriCellsizeMinOf
' Set which raster to get the output extents from.
DirectCast(rasterFunctionArguments, IArithmeticFunctionArguments2).ExtentType = esriExtentType.esriExtentFirstOf

' Create the Raster Function object.
Dim rasterFunction As IRasterFunction
rasterFunction = New ArithmeticFunction()
' Create the Function Raster Dataset object.
Dim functionRasterDataset As IFunctionRasterDataset
functionRasterDataset = New FunctionRasterDataset()
' Create a name object for the Function Raster Dataset.
Dim functionRasterDatasetName As IFunctionRasterDatasetName
functionRasterDatasetName = New FunctionRasterDatasetName()
' Specify the output file name for the new dataset (including the .afr extension at the end).
functionRasterDatasetName.FullName = "c:\temp\ArithmaticFunction.afr"
functionRasterDataset.FullName = functionRasterDatasetName
' Initialize the new Function Raster Dataset with the Raster Function and its arguments.
functionRasterDataset.Init(rasterFunction, rasterFunctionArguments)






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Advanced
ArcGIS for Desktop Advanced ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard